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 <myster@d>
This commit is contained in:
djoslin0 2025-11-18 20:05:07 -08:00 committed by GitHub
parent 6be70deecc
commit a164caa412
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;