diff options
-rw-r--r-- | loslib.c | 4 | ||||
-rw-r--r-- | testes/files.lua | 9 |
2 files changed, 10 insertions, 3 deletions
@@ -260,9 +260,7 @@ static int getfield (lua_State *L, const char *key, int d, int delta) { | |||
260 | res = d; | 260 | res = d; |
261 | } | 261 | } |
262 | else { | 262 | else { |
263 | /* unsigned avoids overflow when lua_Integer has 32 bits */ | 263 | if (!(res >= 0 ? res - delta <= INT_MAX : INT_MIN + delta <= res)) |
264 | if (!(res >= 0 ? (lua_Unsigned)res <= (lua_Unsigned)INT_MAX + delta | ||
265 | : (lua_Integer)INT_MIN + delta <= res)) | ||
266 | return luaL_error(L, "field '%s' is out-of-bound", key); | 264 | return luaL_error(L, "field '%s' is out-of-bound", key); |
267 | res -= delta; | 265 | res -= delta; |
268 | } | 266 | } |
diff --git a/testes/files.lua b/testes/files.lua index 16cf9b6a..78f962e5 100644 --- a/testes/files.lua +++ b/testes/files.lua | |||
@@ -825,8 +825,17 @@ checkerr("missing", os.time, {hour = 12}) -- missing date | |||
825 | if string.packsize("i") == 4 then -- 4-byte ints | 825 | if string.packsize("i") == 4 then -- 4-byte ints |
826 | checkerr("field 'year' is out-of-bound", os.time, | 826 | checkerr("field 'year' is out-of-bound", os.time, |
827 | {year = -(1 << 31) + 1899, month = 1, day = 1}) | 827 | {year = -(1 << 31) + 1899, month = 1, day = 1}) |
828 | |||
829 | checkerr("field 'year' is out-of-bound", os.time, | ||
830 | {year = -(1 << 31), month = 1, day = 1}) | ||
831 | |||
832 | if math.maxinteger > 2^31 then -- larger lua_integer? | ||
833 | checkerr("field 'year' is out-of-bound", os.time, | ||
834 | {year = (1 << 31) + 1900, month = 1, day = 1}) | ||
835 | end | ||
828 | end | 836 | end |
829 | 837 | ||
838 | |||
830 | if not _port then | 839 | if not _port then |
831 | -- test Posix-specific modifiers | 840 | -- test Posix-specific modifiers |
832 | assert(type(os.date("%Ex")) == 'string') | 841 | assert(type(os.date("%Ex")) == 'string') |