[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Silent change to string.pack("cn",...) between 5.3.1 and 5.3.2
- From: Sam Chang <sam.chang@...>
- Date: Fri, 08 Apr 2016 12:25:36 +0800
lua string is more like char buffer, it can contains more \0 in it, so if you want to compare two string as the `common string`, just compare them after a simple trim.
> On Apr 8, 2016, at 12:19, Duane Leslie <parakleta@darkreality.org> wrote:
>
>> On 7 April 2016 at 13:34, Duane Leslie <parakleta@darkreality.org> wrote:
>>> LUA_PACKPADBYTE (not necessarily '\0')
>>>
>>> The padding option is definitely convenient but I dislike padding with LUA_PACKPADBYTE rather than '\0'
>>
>> LUA_PACKPADBYTE *is* defined as '\0'.
>> If you're defining it to something else, don't complain that it's different....
>
> My issue is not so much what it may or may not be defined as, but
> rather that semantically it is not the same as '\0' and this has the
> flow on effect that when it is silently inserted by `pack()` it is
> then loudly returned by `unpack()`.
>
> In all other cases `unpack()` swallows any LUA_PACKPADBYTE but it
> cannot in the case of the fixed string format because it allows any
> data to be inserted and so cannot differentiate padding bytes from
> legitimate data. If you pad the zero terminated string with '\0' then
> you can remove them when unpacking because the semantics are clear.
>
> Regards,
>
> Duane.
>