Avoid gcc snprintf truncation warning in net_udp.cpp

gcc computes a potential value range for game times as [0, 1092] instead
of the [0, 50] that the game uses.  This could be reasonable as the code
was before, but even adding an explicit range check before the usage
does not eliminate the warning.  Avoid the warning by increasing the
size of the buffer to avoid truncation even if the value were 1092.
This commit is contained in:
Kp 2020-12-27 22:03:09 +00:00
parent 3e467e54a3
commit 8e76a5a064

View file

@ -3500,8 +3500,18 @@ protected:
const unsigned game_is_cooperative; const unsigned game_is_cooperative;
char packstring[sizeof("99")]; char packstring[sizeof("99")];
std::array<char, sizeof("65535")> portstring; std::array<char, sizeof("65535")> portstring;
char srinvul[sizeof("Reactor life: 50 min")]; /* Reactor life and Maximum time are stored in a uint32_t, and have
char PlayText[sizeof("Max time: 50 min")]; * a theoretical maximum of 1092 after converting from internal game
* time (seconds in fixed point) to minutes. User input limitations
* prevent setting a value higher than 50 minutes. Even if the code
* is modified to verify a maximum value of 50 immediately before
* formatting it, the gcc value range propagation pass fails to
* detect the reduced range and issues a warning as if the value
* could be 1092. Eliminate the bogus warning by using a buffer
* large enough for the theoretical maximum.
*/
char srinvul[sizeof("Reactor life: 1092 min")];
char PlayText[sizeof("Max time: 1092 min")];
char SpawnInvulnerableText[sizeof("Invul. Time: 0.0 sec")]; char SpawnInvulnerableText[sizeof("Invul. Time: 0.0 sec")];
char SecludedSpawnText[sizeof("Use 0 Furthest Sites")]; char SecludedSpawnText[sizeof("Use 0 Furthest Sites")];
char KillText[sizeof("Kill goal: 000 kills")]; char KillText[sizeof("Kill goal: 000 kills")];