From a164caa412b37fbd2bb3ea575adb273abfb1011e Mon Sep 17 00:00:00 2001 From: djoslin0 Date: Tue, 18 Nov 2025 20:05:07 -0800 Subject: [PATCH] Fix negative zero network_send() edgecase (#1024) Lua mods in very rare scenarios would send a value of -0 over the network, and receive MIN_U64 due to an incorrect guess at the variable type in an LNT. --------- Co-authored-by: MysterD --- src/pc/lua/smlua_utils.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/pc/lua/smlua_utils.c b/src/pc/lua/smlua_utils.c index 496afb87b..c6bd63a20 100644 --- a/src/pc/lua/smlua_utils.c +++ b/src/pc/lua/smlua_utils.c @@ -241,19 +241,14 @@ struct LSTNetworkType smlua_to_lnt(lua_State* L, int index) { int valueType = lua_type(L, index); if (valueType == LUA_TNUMBER) { - lnt.type = LST_NETWORK_TYPE_INTEGER; - lnt.value.integer = lua_tointeger(L, index); - lnt.size = sizeof(u8) + sizeof(long long); - - if (lnt.value.integer == 0) { + if (lua_isinteger(L, index)) { + lnt.type = LST_NETWORK_TYPE_INTEGER; + lnt.value.integer = lua_tointeger(L, index); + lnt.size = sizeof(u8) + sizeof(long long); + } else { lnt.type = LST_NETWORK_TYPE_NUMBER; lnt.value.number = lua_tonumber(L, index); lnt.size = sizeof(u8) + sizeof(double); - - if (lnt.value.number == 0) { - lnt.type = LST_NETWORK_TYPE_INTEGER; - lnt.size = sizeof(u8) + sizeof(long long); - } } gSmLuaConvertSuccess = true; return lnt;