diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2021-07-29 20:22:14 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-29 20:22:14 +0200 |
commit | 41114a2a27047bf1884e092b98c6298c128eb2f0 (patch) | |
tree | e0af00022d38df4ba34dab48d7c36590d7b5fbbc /src/if_lua.c | |
parent | 83cd0156e01b5befadf12ee66bc26436ee8d023f (diff) | |
download | vim-git-41114a2a27047bf1884e092b98c6298c128eb2f0.tar.gz |
patch 8.2.3244: Lua 5.3 print() with a long string crashesv8.2.3244
Problem: Lua 5.3 print() with a long string crashes.
Solution: Use a growarray instead of a Lua buffer. (Yegappan Lakshmanan,
closes #8655)
Diffstat (limited to 'src/if_lua.c')
-rw-r--r-- | src/if_lua.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/if_lua.c b/src/if_lua.c index 581040163..a3bb0b96b 100644 --- a/src/if_lua.c +++ b/src/if_lua.c @@ -1720,11 +1720,12 @@ static const luaL_Reg luaV_Window_mt[] = { static int luaV_print(lua_State *L) { - int i, n = lua_gettop(L); // nargs - const char *s; - size_t l; - luaL_Buffer b; - luaL_buffinit(L, &b); + int i, n = lua_gettop(L); // nargs + const char *s; + size_t l; + garray_T msg_ga; + + ga_init2(&msg_ga, 1, 128); lua_getglobal(L, "tostring"); for (i = 1; i <= n; i++) { @@ -1735,13 +1736,19 @@ luaV_print(lua_State *L) if (s == NULL) return luaL_error(L, "cannot convert to string"); if (i > 1) - luaL_addchar(&b, ' '); // use space instead of tab - luaV_addlstring(&b, s, l, 0); + ga_append(&msg_ga, ' '); // use space instead of tab + ga_concat_len(&msg_ga, (char_u *)s, l); lua_pop(L, 1); } - luaL_pushresult(&b); + // Replace any "\n" with "\0" + for (i = 0; i < msg_ga.ga_len; i++) + if (((char *)msg_ga.ga_data)[i] == '\n') + ((char *)msg_ga.ga_data)[i] = '\0'; + lua_pushlstring(L, msg_ga.ga_data, msg_ga.ga_len); if (!got_int) luaV_msg(L); + + ga_clear(&msg_ga); return 0; } |