uint32_t a, b;
...
uint32_t c = a * b; // could result in undefined behavior if sizeof(int)>4 (h/t @RichFelker)
-
-
@RichFelker@jduck@SwissHttp You need a bit larger numbers to get overflow. Like: uint16_t a=65535, b=65535, c =a*b;. -
@ch3root@RichFelker@SwissHttp I see. does it actually manifest in badness? wrong result? -
.
@jduck@RichFelker@SwissHttp All kinds of badness. Following program (compiled with gcc 4.9 -O2 or clang 3.5 -O1) prints negative number.. -
.
@jduck@RichFelker@SwissHttp ...even tho it explicitly protects against it. I guess you can imagine consequences of this in critical code. -
.
@jduck@RichFelker@SwissHttp#include <stdio.h> int main(int c, char **v) { unsigned short m=-c; int n=m*m; if (n>=0) printf("%d\n", n); }
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.