Skip to content

Commit 7a92e1b

Browse files
kevinbackhouseneheb
authored andcommitted
Don't allow INT_MIN (0x80000000) because it can cause a UBSAN failure in std::gcd().
1 parent d15fdee commit 7a92e1b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/types.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,8 @@ Rational floatToRationalCast(float f) {
615615
// below. (INT_MAX can be represented accurately as a double, but
616616
// gets rounded when it's converted to float.)
617617
const double d = f;
618-
const bool in_range = std::numeric_limits<int32_t>::min() <= d && d <= std::numeric_limits<int32_t>::max();
618+
// Don't allow INT_MIN (0x80000000) because it can cause a UBSAN failure in std::gcd().
619+
const bool in_range = std::numeric_limits<int32_t>::min() < d && d <= std::numeric_limits<int32_t>::max();
619620
if (!in_range) {
620621
return {d > 0 ? 1 : -1, 0};
621622
}

0 commit comments

Comments
 (0)