From c262d3f532bf02a428afd23e97a9a95db2a5a897 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 15 Oct 2025 20:36:29 +0200 Subject: [PATCH] prevent potential 0 division in CV_AddValue as repoted by clang-tidy --- src/command.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/command.c b/src/command.c index ee3b36247..47bd521b0 100644 --- a/src/command.c +++ b/src/command.c @@ -1913,13 +1913,14 @@ void CV_AddValue(consvar_t *var, INT32 increment) max = (M_SecretUnlocked(SECRET_HARDSPEED) ? 3 : 2); } #ifdef PARANOIA - if (currentindice == -1) - I_Error("CV_AddValue: current value %d not found in possible value\n", - var->value); + if (currentindice == -1 || max == 0) + I_Error("CV_AddValue: current value %d not found in possible value\n", var->value); #endif - - newindice = (currentindice + increment + max) % max; - CV_Set(var, var->PossibleValue[newindice].strvalue); + if (max > 0) + { + newindice = (currentindice + increment + max) % max; + CV_Set(var, var->PossibleValue[newindice].strvalue); + } } } else