J
Jeffrey Walton
Hi All,
I'm building test cases for a third party library, and wanted a
clarification. Searching the FAQ did not turn up hits for division and
modulo or reduction [1].
INT_MIN / -1 = overflow since the result is INT_MAX+1. For example
(using int16 types):
32768 = -32768 / -1
Below, the result is within the reange of the datattype.
32767 = -32768 % -1
However Seacord tells us the result is undefined in CERT's Secure
Programming Guide [2]. Also, I seem to recall that reduction is
defined similar to division for consistency.
What is the state of modular reduction (eg, INT_MIN % -1)?
Jeff
[1] http://www.parashift.com/c++-faq-lite/
[2]
https://www.securecoding.cert.org/c...ations+do+not+result+in+divide-by-zero+errors
I'm building test cases for a third party library, and wanted a
clarification. Searching the FAQ did not turn up hits for division and
modulo or reduction [1].
INT_MIN / -1 = overflow since the result is INT_MAX+1. For example
(using int16 types):
32768 = -32768 / -1
Below, the result is within the reange of the datattype.
32767 = -32768 % -1
However Seacord tells us the result is undefined in CERT's Secure
Programming Guide [2]. Also, I seem to recall that reduction is
defined similar to division for consistency.
What is the state of modular reduction (eg, INT_MIN % -1)?
Jeff
[1] http://www.parashift.com/c++-faq-lite/
[2]
https://www.securecoding.cert.org/c...ations+do+not+result+in+divide-by-zero+errors