Bug 14785 – Some corner cases are not handled properly by core.checkedint.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-07-07T22:48:00Z
Last change time
2015-10-04T18:19:13Z
Keywords
patch, pull
Assigned to
nobody
Creator
thomas.bockman

Comments

Comment #0 by thomas.bockman — 2015-07-07T22:48:49Z
** Test cases that currently fail ** import core.checkedint; void main(string[] args) { bool overflow = false; assert(subs(-1L, long.min, overflow) == long.max); assert(!overflow); // Assertion failure overflow = false; assert(muls(-1L, long.min, overflow) == long.min); // FPE assert(overflow); } ** Proposed fix ** long subs(long x, long y, ref bool overflow) { long r = cast(ulong)x - cast(ulong)y; if (x < 0 && y >= 0 && r >= 0 || x >= 0 && y < 0 && (r < 0 || y == long.min)) overflow = true; return r; } long muls(long x, long y, ref bool overflow) { long r = cast(ulong)x * cast(ulong)y; enum not0or1 = ~1L; if((x & not0or1) && ((r == y)? r : (r / x) != y)) overflow = true; return r; }
Comment #1 by dlang-bugzilla — 2015-08-31T12:13:19Z
(In reply to thomas.bockman from comment #0) > ** Proposed fix ** Please submit this as a pull request! http://wiki.dlang.org/Pull_Requests
Comment #2 by thomas.bockman — 2015-08-31T18:59:52Z
I finally got around to doing so a few days ago: [PR #1365](https://github.com/D-Programming-Language/druntime/pull/1365)
Comment #3 by dlang-bugzilla — 2015-09-01T00:13:49Z
Great, thanks!
Comment #4 by github-bugzilla — 2015-09-06T14:52:55Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/799a68968ee5c92452b863851fa32d762cba180f Fix Issue 14785 - Some corner cases are not handled properly by core.checkedint. https://github.com/D-Programming-Language/druntime/commit/acb86115d1d1605f5000dd0c2e8308c451716b44 Merge pull request #1365 from tsbockman/issue_14785 Fix Issue 14785 - Some corner cases are not handled properly by core.checkedint.
Comment #5 by github-bugzilla — 2015-10-04T18:19:13Z