Merge pull request #11244 from WalterBright/fix20903

fix Issue 20903 - seg fault on long signed divide overflow
merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
This commit is contained in:
The Dlang Bot 2020-06-07 13:37:42 +02:00 committed by GitHub
commit 9c8e7bbaf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View file

@ -1094,6 +1094,10 @@ version (MARS)
div0:
error(e.Esrcpos.Sfilename, e.Esrcpos.Slinnum, e.Esrcpos.Scharnum, "divide by zero");
break;
overflow:
error(e.Esrcpos.Sfilename, e.Esrcpos.Slinnum, e.Esrcpos.Scharnum, "integer overflow");
break;
}
}
}
@ -1104,6 +1108,7 @@ else
if (!boolres(e2))
{
div0:
overflow:
version (SCPP)
synerr(EM_divby0);
break;
@ -1183,6 +1188,8 @@ else
rem = (cast(targ_ullong) l1) % (cast(targ_ullong) l2);
quo = (cast(targ_ullong) l1) / (cast(targ_ullong) l2);
}
else if (l1 == 0x8000_0000_0000_0000 && l2 == -1L)
goto overflow; // overflow
else
{
rem = l1 % l2;

View file

@ -0,0 +1,15 @@
/* REQUIRED_ARGS: -O -m64
* TEST_OUTPUT:
---
fail_compilation/test20903.d(14): Error: integer overflow
---
*/
// http://issues.dlang.org/show_bug.cgi?id=20903
long test()
{
long r = 0x8000_0000_0000_0000L;
long x = -1L;
return r / x;
}