@@ -21,6 +21,9 @@ static lua_Number
2121check_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
3235check_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