mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-24 02:09:28 +00:00
LibJS+AK: Fix integer overflow UB on (any Int32 - -2147483648)
It wasn't safe to use addition_would_overflow(a, -b) to check if subtraction (a - b) would overflow, since it doesn't cover this case. I don't know why we didn't have subtraction_would_overflow(), so this patch adds it. :^)
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
test("basic integer overflow correctness", () => {
|
||||
expect(2147483647 + 1).toBe(2147483648);
|
||||
expect(2147483648 - 1).toBe(2147483647);
|
||||
expect(0 - 2147483647).toBe(-2147483647);
|
||||
expect(0 - 2147483648).toBe(-2147483648);
|
||||
expect(0 - -2147483647).toBe(2147483647);
|
||||
expect(0 - -2147483648).toBe(2147483648);
|
||||
expect(0 + -2147483647).toBe(-2147483647);
|
||||
expect(0 + -2147483648).toBe(-2147483648);
|
||||
});
|
||||
Reference in New Issue
Block a user