From b975eedd9b1030815d7e6395d93b9edc7922cf6c Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 26 Apr 2021 14:00:34 -0700 Subject: [PATCH] Fix two bugs with Lua MIN, MAX Plus cvars 1) Any cvar without MIN, MAX would be disallowed; now check that at least one of those values is actually present. 2) Handle value index properly when shifting array. --- src/lua_consolelib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index e839d4e15..51e83d792 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -400,23 +400,23 @@ static int lib_cvRegisterVar(lua_State *L) { memmove(&cvpv[2], &cvpv[0], i * sizeof *cvpv); + i += 2; } cvpv[n].strvalue = MINMAX[n]; minmax_unset &= ~(1 << n); } else { - n = i; + n = i++; cvpv[n].strvalue = Z_StrDup(strval); } cvpv[n].value = (INT32)lua_tonumber(L, 6); - i++; lua_pop(L, 1); } - if (minmax_unset) + if (minmax_unset && minmax_unset != 3) FIELDERROR("PossibleValue", "custom PossibleValue table requires requires both MIN and MAX keys if one is present"); cvpv[i].value = 0;