Harden offsetCardCounter() against signed-int overflow

Replace the raw oldValue + offset sum with addClamped(), clamping to [0, MAX_COUNTER_VALUE] without overflow.
This commit is contained in:
DawnFire42 2026-06-26 11:49:52 -04:00
parent 3aa94b4f31
commit 2a1b505913
No known key found for this signature in database
GPG key ID: 24BB855EE2911B33
2 changed files with 11 additions and 7 deletions

View file

@ -7,8 +7,8 @@
/**
* @brief Overflow-safe clamped addition: returns value + delta bounded to [minValue, maxValue].
*
* Uses a 64-bit intermediate so the addition itself cannot overflow int. Shared by the
* counter arithmetic in Server_Card and Server_Counter so both stay in sync.
* Uses a 64-bit intermediate so the addition cannot overflow int. Shared by the counter
* arithmetic in Server_Card, Server_Counter, and PlayerActions.
*
* @note Requires minValue <= maxValue. Bounds come from trusted compile-time call sites;
* qBound() asserts this internally in debug builds.