I think this is a bug.
In Lua 5.1 and LuaJIT 2.0, string.format
formats one item at a time (using the sprintf
provided by the host C runtime.) It then calls strlen
to update the length of the output string. Since strlen
stops at the null character, this character will be overwritten.
This is documented behaviour for %s
, but probably unintentional for %c
This is fixed in Lua 5.2. I wouldn't expect any more updates to 5.1.