mirror of
https://github.com/gbdev/rgbds.git
synced 2026-12-05 23:58:39 +00:00
Avoid signed overflow in RGBLINK's +, -, and * (#2060)
RGBASM computes these with unsigned arithmetic and casts back, since signed overflow is UB in C++, but RGBLINK's RPN evaluator used `int32_t` directly, so `src/link/patch.cpp` tripped UBSan on lines 117, 121, and 124. Share the three operators through `opmath.cpp` so both evaluators stay in step.
This commit is contained in:
1 parent
fdd6cece30
commit
631ef003e7
7 files changed
+35
-7
No files matched your search
@@ -0,0 +1,9 @@
|
||||
def fzero equs "startof(\"test\")"
|
||||
section "test", rom0
|
||||
; Signed overflow is undefined behavior, so these must wrap around instead
|
||||
dl $7fff_ffff + ({fzero} + 1)
|
||||
dl $8000_0000 - ({fzero} + 1)
|
||||
dl $7fff_ffff * ({fzero} + 3)
|
||||
|
||||
; XXX: We rely on this landing at address $0000, which isn't *guaranteed*...
|
||||
assert startof("test") == 0
|
||||
Whitespace-only changes.
Binary file not shown.
Reference in new issue
Block a user