fix(bitmap): handle INT32_MIN safely in LOCAL_ABS macro #143

Merged
OragonEfreet merged 1 commit from fix/dib-int32-min-ub into main 2026-06-03 19:59:02 +02:00
Owner

Fix undefined behavior when negating INT32_MIN by using unsigned
arithmetic instead. The old macro (uint32_t)(-(x)) would invoke
UB when x is INT32_MIN because -INT32_MIN overflows int32_t.

The new approach casts to uint32_t first, then uses unsigned
subtraction: (uint32_t)0 - (uint32_t)(x), which is well-defined.

Fix undefined behavior when negating INT32_MIN by using unsigned arithmetic instead. The old macro `(uint32_t)(-(x))` would invoke UB when x is INT32_MIN because -INT32_MIN overflows int32_t. The new approach casts to uint32_t first, then uses unsigned subtraction: `(uint32_t)0 - (uint32_t)(x)`, which is well-defined.
fix(bitmap): handle INT32_MIN safely in LOCAL_ABS macro
All checks were successful
Documentation / build-docs (pull_request) Successful in 8s
QA / cert (pull_request) Successful in 27s
Build and Test / linux-linux-gcc / shared (pull_request) Successful in 16s
Build and Test / linux-linux-gcc / static (pull_request) Successful in 16s
Build and Test / linux-windows-mingw / shared (pull_request) Successful in 25s
Build and Test / linux-windows-mingw / static (pull_request) Successful in 26s
3f0b62f6a1
Fix undefined behavior when negating INT32_MIN by using unsigned
arithmetic instead. The old macro `(uint32_t)(-(x))` would invoke
UB when x is INT32_MIN because -INT32_MIN overflows int32_t.

The new approach casts to uint32_t first, then uses unsigned
subtraction: `(uint32_t)0 - (uint32_t)(x)`, which is well-defined.
OragonEfreet added this to the 1.0 milestone 2026-06-03 17:57:12 +02:00
OragonEfreet deleted branch fix/dib-int32-min-ub 2026-06-03 19:59:02 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
OragonEfreet/banjo!143
No description provided.