Opened 4 years ago
Last modified 4 years ago
#13558 new Bugs
gcd(INT_MIN, INT_MIN) crashes
| Reported by: | Owned by: | Daryle Walker | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | integer |
| Version: | Boost 1.67.0 | Severity: | Problem |
| Keywords: | Cc: | evaned@… |
Description
The following produces a SIGFPE for me:
#include <iostream> #include <climits> #include <boost/integer/common_factor_rt.hpp> int main() { std::cout << boost::integer::gcd(INT_MIN, INT_MIN); }
because it simplifies gcd(INT_MIN, INT_MIN) => gcd(INT_MIN % INT_MIN, INT_MIN) => gcd(0, INT_MIN) => gcd(0, INT_MIN % 0) => gcd(0, SIGFPE)`.
I'm actually not sure what the right behavior is (the documented behavior is that the return is always positive, and, for example, gcd(-2, -2) returns 2, but obviously you can't do that here).
Boost 1.63 returned INT_MIN in this case, which seems like the best answer.
Responsible commit: https://github.com/boostorg/integer/commit/beb68718640150f67fe5671bbbb7848d9e7170b8
Note:
See TracTickets
for help on using tickets.
