Skip to content

Commit 6609ed7

Browse files
committed
Add boundary check
1 parent ec39f78 commit 6609ed7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

include/boost/int128/cstdlib.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ constexpr i128div_t div(const int128_t x, const int128_t y) noexcept
7373
const auto abs_lhs {static_cast<uint128_t>(abs(x))};
7474
const auto abs_rhs {static_cast<uint128_t>(abs(y))};
7575

76-
const auto unsigned_res {div(abs_lhs, abs_rhs)};
76+
if (abs_rhs > abs_lhs)
77+
{
78+
return {0, x};
79+
}
7780

81+
const auto unsigned_res {div(abs_lhs, abs_rhs)};
7882

7983
const auto negative_quot {(x.high < 0) != (y.high < 0)};
8084
#if defined(_MSC_VER) && !defined(__GNUC__)

0 commit comments

Comments
 (0)