[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string.format's %s and null bytes
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sun, 2 Aug 2015 11:55:01 -0300
> It's due to this check in lstrlib.c (this one taken from 5.1, but 5.2
> and 5.3 are pretty much the same):
>
> size_t l;
> const char *s = luaL_checklstring(L, arg, &l);
> if (!strchr(form, '.') && l >= 100) {
> /* no precision and string is too long to be formatted;
> keep original string */
> [...]
> }
> else {
> sprintf(buff, form, s);
> break;
> }
>
> [...]
>
> Btw, In the current code, I don't think that `form` can ever contain a
> '.' when l > 99, so the first predicate can be ignored.
I think the following format has '.' in 'form' and l > 99 (and needs that
test to be properly formatted):
string.format("%9.5s", string.rep("a", 1000))
-- Roberto