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

Re: Having fun with the following C code (UB)



On 14.04.2014 14:26, Raphael Geissert wrote:
> Russ Allbery wrote:
>> Shachar Shemesh <shachar@debian.org> writes:
>>> Do you really want to get a "Warning: signed integer overflow yields
>>> undefined behavior" on this function?
>>
>> I would certainly like to be able to enable such a thing.  I write a lot
>> of code where I'd love the compiler to double-check that I've established
>> bounds checks on a and b before doing the addition that guarantee that it
>> won't overflow.
> 
> Not quite to that point, but you might be interested in the UBS:
> 
> http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation
> 
> More specifically, two options: -fsanitize=undefined and -fsanitize=integer
> 
> And some nice examples:
> http://blog.regehr.org/archives/1054
> http://blog.regehr.org/archives/963
> 
> Cheers,
> 

fyi, gcc-4.9 which is currently available as a release candidate also
has the undefined behavior (and address/thread) sanitizer included, it
is enabled the same way with -fsanitize=...
http://gcc.gnu.org/gcc-4.9/changes.html

but it can only detect it when undefined behavior really occurs (and
ubsan has a check for it), which is not often the case in regular
testsuites or normal application runs.
It is probably most useful combined with fuzz testing to trigger code
paths you didn't account for.


Reply to: