Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 1f4d6a2

Browse files
committed
fix signed multiply overflow detection
1 parent cc36127 commit 1f4d6a2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/core/checkedint.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ long muls()(long x, long y, ref bool overflow)
572572
{
573573
immutable long r = cast(ulong)x * cast(ulong)y;
574574
enum not0or1 = ~1L;
575-
if ((x & not0or1) && ((r == y)? r : (r / x) != y))
575+
if ((x & not0or1) &&
576+
((r == y) ? r != 0
577+
: (r == 0x8000_0000_0000_0000 && x == -1L) || ((r / x) != y)))
576578
overflow = true;
577579
return r;
578580
}

0 commit comments

Comments
 (0)