Discussion:
signed integer overflow in cache.c
123
2012-06-15 21:31:01 UTC
Permalink
In function Cache_client_enqueue variable ClientKey is incremented and
checked for negative values after that (in case of overflow).

Even though overflow is unlikely, signed integer overflow results in
wraparound on most systems and gcc don't seem to optimize away
overflow check even with -O3 (it only inlines Cache_client_enqueue in
my case) it is better to avoid overflow completely as there are other
compilers and compiler versions.
123
2012-06-15 21:34:19 UTC
Permalink
And in case someone thinks it is non-issue:
http://thiemonagel.de/2010/01/signed-integer-overflow/
Jorge Arellano Cid
2012-06-18 14:29:07 UTC
Permalink
Post by 123
In function Cache_client_enqueue variable ClientKey is incremented and
checked for negative values after that (in case of overflow).
Even though overflow is unlikely, signed integer overflow results in
wraparound on most systems and gcc don't seem to optimize away
overflow check even with -O3 (it only inlines Cache_client_enqueue in
my case) it is better to avoid overflow completely as there are other
compilers and compiler versions.
+1.

Agreed.

I'd add a comment to remember this. e.g.

/* integer wraparound/overflow is not defined by C/C++ standards */
--
Cheers
Jorge.-
Loading...