Re: gcc warn when pointers not checked non-null before de-referencing.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2021-06-16 at 14:01 +0100, Jonny Grant wrote:

> Chris Latner also mentioned integer overflow being undefined, that
> crops up too. There's no easy solution right, we need to hand write
> code the checks?  It's human-error prone if we need to manually code
> each check. throwing in C++, or handling in C.
> 
> if(N >= INT_MAX)
> {
>     throw std::overflow_error("N >= INT_MAX would overflow in for
> loop");
> }
> 
> for (i = 0; i <= N; ++i)
> {
> // ...
>  }

For debugging use -fsanitize=undefined.

And this is buggy anyway, no matter if there is an UB:

for (unsigned i = 0; i <= N; i++)
    make_some_side_effect_without_any_undefined_behavior(i);

If N may be UINT_MAX, this is not UB, but a dead loop. Programming is
just human-error prone, even if you use "some programming language
claimed to be able to eliminate many human errors" (I'll not say its
name, to prevent a flame war).
-- 
Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux