You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since time is an integer, it could take values from -2147483648 to 2147483647, but if I try to do
TIME.new(-2147483648)
the following error is returned
Could not read unix timestamp -2.147484e+09
While this error is not returned in the case I use
TIME.new("-2147483648")
This seems due to some conversion from number to string done internally in lua since, as stated in the documentation, both number and strings are seen as string from lua_isstring function (making also the lua_isnumber branching useless)
lerror(L, "Could not read unix timestamp %s", arg);
returnNULL;
} elseif (l_result<INT_MIN||l_result>INT_MAX) {
free(result);
lerror(L, "Could not read unix timestamp %s out of range", arg);
returnNULL;
}
*result= (ztime_t)l_result;
goto end;
}
// number argument, import
if(lua_isnumber(L, 1)) {
lua_Numbernumber=lua_tonumber(L, 1);
*result= (int)number;
goto end;
}
octet*o=o_arg(L, n);
if(o) {
if(o->len!=sizeof(ztime_t)) {
free(result);
zerror(L, "Wrong size timestamp %s", __func__);
returnNULL;
}
memcpy(result, o->val, sizeof(ztime_t));
o_free(L, o);
goto end;
}
end:
if(result) Z->memcount_times++;
returnresult;
}
and thus they both pass thorugh the lua_tostring function. I tried also to move the branch with lua_isnumber before the lua_isstring one, but it seemed that after a certain number, lua was not able to read them correctly.
Thus at the moment, if we use numbers in input we are only loosing the time -2147483648 and using strings in input we should not lose anything. Anyway interesting to notice and maybe look further into it in case any other problems with numbers came up.
The text was updated successfully, but these errors were encountered:
jaromil
changed the title
Time parsing not fully working
Time parsing 32bit corner-case
Apr 12, 2024
Since time is an integer, it could take values from
-2147483648
to2147483647
, but if I try to dothe following error is returned
While this error is not returned in the case I use
This seems due to some conversion from number to string done internally in lua since, as stated in the documentation, both number and strings are seen as string from
lua_isstring
function (making also the lua_isnumber branching useless)Zenroom/src/zen_time.c
Lines 74 to 121 in ca02f6c
and thus they both pass thorugh the
lua_tostring
function. I tried also to move the branch withlua_isnumber
before thelua_isstring
one, but it seemed that after a certain number, lua was not able to read them correctly.Thus at the moment, if we use numbers in input we are only loosing the time
-2147483648
and using strings in input we should not lose anything. Anyway interesting to notice and maybe look further into it in case any other problems with numbers came up.The text was updated successfully, but these errors were encountered: