mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-29 17:32:17 -07:00
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:
parent
3aa94b4f31
commit
2a1b505913
2 changed files with 11 additions and 7 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue