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

Commit d774ab9

Browse files
authored
Merge pull request #3126 from WalterBright/muls-overflow
fix signed multiply overflow detection merged-on-behalf-of: Rainer Schuetze <rainers@users.noreply.github.com>
2 parents cc36127 + 1f4d6a2 commit d774ab9

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)