iryont/lua-struct

unpack('c3', ...) returns 4 chars, i.e. one too many

EnTerr opened this issue · 1 comments

Like subject says, unpacking fixed-size string returns one too many chars. If you ask for N, you'll get N+1. Note the iterator was not (d)effected, i.e. is advanced by the correct length N and following fields are not messed up.

It's a trivial bug, the fix is in to subtract 1 in this one line
https://github.com/iryont/lua-struct/blob/master/struct.lua#L188

188-      table.insert(vars, stream:sub(iterator, iterator + tonumber(n)))
188+      table.insert(vars, stream:sub(iterator, iterator + tonumber(n)-1))

Hey

Thanks :) However, I do suggest to create pull request the next time you have a solution for a bug or for some other issue. It should speed things up since I'm hardly available nowadays.