[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why does string.format() limit width to two digits?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 18 Jan 2023 17:13:21 -0300
> I was wondering why Lua's string.format() limits the width and precision fields to two digits. E.g. this doesn't work in Lua because we use a width of 100 (99 works fine):
>
> string.format('%100s', 'hello world')
>
> Is there any particular reason why Lua imposes this limit on string.format()? I'm just wondering because this restriction sometimes makes it difficult to port C code to Lua.
It is a simple and secure way to limit the maximum size of formatted
items, to avoid buffer overflow. (Do you really need larger values?)
See comments around [1].
[1] https://www.lua.org/source/5.4/lstrlib.c.html#MAX_ITEMF
-- Roberto