lua-users home
lua-l archive

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


> 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