News for hackers. Stuff that matters.
Re:Solutions to Integer Overflow by mzs on Monday September 05, 2016 @02:03PM (#12431487)
It's worse than you might expect, try it with unsigned int ;)

    $ cc -O3 foo.c
    $ ./a.out 
    5e574b68
    $ cat foo.c 
    #include <stdio.h>
    
    int main(int argc, char ** argv) {
      unsigned int a = 1;
      unsigned int b = 0;
      printf("%x\n", a/b);
    }
Yes overflow wraps on unsigned as defined, but that example is divide-by-zero which is UB for unsigned too and the compiler is free to optimize there, which LLVM does.

There are no comments on this comment yet.