mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 05:00:16 +03:00
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:
commit
9c8e7bbaf2
2 changed files with 22 additions and 0 deletions
|
@ -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;
|
||||
|
|
15
test/fail_compilation/test20903.d
Normal file
15
test/fail_compilation/test20903.d
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue