Skip to content

Commit 228e044

Browse files
committed
Underflow when converting signed to unsigned
1 parent 6eeed8d commit 228e044

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

LuaGObject/marshal.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ static lua_Number
2121
check_integer(lua_State *L, int narg, lua_Number val_min, lua_Number val_max)
2222
{
2323
lua_Number val = luaL_checknumber(L, narg);
24+
/* If the value is negative and the target type is unsigned, return it so it underflows. */
25+
if (val_min == 0 && val < 0)
26+
return val;
2427
if (val < val_min || val > val_max) {
2528
lua_pushfstring(L, "%f is out of <%f, %f>", val, val_min, val_max);
2629
luaL_argerror(L, narg, lua_tostring(L, -1));
@@ -32,6 +35,9 @@ static lua_Integer
3235
check_integer(lua_State *L, int narg, lua_Integer val_min, lua_Integer val_max)
3336
{
3437
lua_Integer val = luaL_checkint(L, narg);
38+
/* If the value is negative and the target type is unsigned, return it so it underflows. */
39+
if (val_min == 0 && val < 0)
40+
return val;
3541
if (val < val_min || val > val_max) {
3642
lua_pushfstring(L, "%I is out of <%I, %I>", val, val_min, val_max);
3743
luaL_argerror(L, narg, lua_tostring(L, -1));

0 commit comments

Comments
 (0)