Skip to content

Commit

Permalink
Fixed string.format with substrings
Browse files Browse the repository at this point in the history
  • Loading branch information
MCJack123 committed Oct 31, 2021
1 parent 0a4bfb8 commit fe82e7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/lapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,13 @@ LUA_API int lua_toboolean (lua_State *L, int idx) {

LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
StkId o = index2adr(L, idx);
if (ttissubstr(o) && len != NULL) {
/* if using lua_tostring, we need to convert to normal string so the cstring ends with \0 */
/* otherwise, we can keep the substring intact */
/*if (ttissubstr(o) && len != NULL) {
/ * ~~if using lua_tostring, we need to convert to normal string so the cstring ends with \0 * /
/ * otherwise, we can keep the substring intact~~ * /
/ * EDIT: this breaks Lua spec - we're always doing this * /
*len = ssvalue(o)->len;
return getstr(ssvalue(o)->str) + ssvalue(o)->offset;
}
}*/
if (!ttisstring(o)) {
lua_lock(L); /* `luaV_tostring' may create a new string */
if (!luaV_tostring(L, o)) { /* conversion failed? */
Expand Down
2 changes: 1 addition & 1 deletion src/lstrlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ static int str_format (lua_State *L) {
continue; /* skip the `addsize' at the end */
}
else {
sprintf(buff, form, s);
snprintf(buff, MAX_ITEM, form, s);
lua_pop(L, 1);
break;
}
Expand Down

0 comments on commit fe82e7d

Please sign in to comment.