mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-29 13:42:00 +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:
parent
1de475b404
commit
b2e6843055
Notes:
sideshowbarker
2024-07-17 07:31:31 +09:00
Author: https://github.com/awesomekling
Commit: b2e6843055
Pull-request: https://github.com/SerenityOS/serenity/pull/24354
3 changed files with 27 additions and 1 deletions
|
@ -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);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue