lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 12/03/2020 20.06, cherue wrote:
> Hello,
> 
> I found a bug in string.unpack:
> 
> ```
> Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio
>> string.unpack("I4", "\255\255\255\255")
> 4294967295	5
>> string.unpack("I8", "\255\255\255\255\255\255\255\255")
> -1	9
>> string.unpack("I8", "\255\255\255\255\255\255\255\127")
> 9223372036854775807	9
>> string.unpack("I8", "\255\255\255\255\255\255\255\128")
> -9151314442816847873	9
> ```
> 
> I tried looking for the cause but I am not fluent in C. Maybe something about lua_Integer?
> 

So where is the bug?

In my point of view you've got quite consistent results
for two's-complement little-endian integer encoding.

-- Martin