Mercurial > vim
comparison src/if_lua.c @ 25415:02d1b2817585 v8.2.3244
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Commit: https://github.com/vim/vim/commit/41114a2a27047bf1884e092b98c6298c128eb2f0
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Jul 29 20:22:14 2021 +0200
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Problem: Lua 5.3 print() with a long string crashes.
Solution: Use a growarray instead of a Lua buffer. (Yegappan Lakshmanan,
closes #8655)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 29 Jul 2021 20:30:08 +0200 |
parents | 241d26b17192 |
children | 9947b7e4b319 |
comparison
equal
deleted
inserted
replaced
25414:45926a62bafd | 25415:02d1b2817585 |
---|---|
1718 // ======= Vim module ======= | 1718 // ======= Vim module ======= |
1719 | 1719 |
1720 static int | 1720 static int |
1721 luaV_print(lua_State *L) | 1721 luaV_print(lua_State *L) |
1722 { | 1722 { |
1723 int i, n = lua_gettop(L); // nargs | 1723 int i, n = lua_gettop(L); // nargs |
1724 const char *s; | 1724 const char *s; |
1725 size_t l; | 1725 size_t l; |
1726 luaL_Buffer b; | 1726 garray_T msg_ga; |
1727 luaL_buffinit(L, &b); | 1727 |
1728 ga_init2(&msg_ga, 1, 128); | |
1728 lua_getglobal(L, "tostring"); | 1729 lua_getglobal(L, "tostring"); |
1729 for (i = 1; i <= n; i++) | 1730 for (i = 1; i <= n; i++) |
1730 { | 1731 { |
1731 lua_pushvalue(L, -1); // tostring | 1732 lua_pushvalue(L, -1); // tostring |
1732 lua_pushvalue(L, i); // arg | 1733 lua_pushvalue(L, i); // arg |
1733 lua_call(L, 1, 1); | 1734 lua_call(L, 1, 1); |
1734 s = lua_tolstring(L, -1, &l); | 1735 s = lua_tolstring(L, -1, &l); |
1735 if (s == NULL) | 1736 if (s == NULL) |
1736 return luaL_error(L, "cannot convert to string"); | 1737 return luaL_error(L, "cannot convert to string"); |
1737 if (i > 1) | 1738 if (i > 1) |
1738 luaL_addchar(&b, ' '); // use space instead of tab | 1739 ga_append(&msg_ga, ' '); // use space instead of tab |
1739 luaV_addlstring(&b, s, l, 0); | 1740 ga_concat_len(&msg_ga, (char_u *)s, l); |
1740 lua_pop(L, 1); | 1741 lua_pop(L, 1); |
1741 } | 1742 } |
1742 luaL_pushresult(&b); | 1743 // Replace any "\n" with "\0" |
1744 for (i = 0; i < msg_ga.ga_len; i++) | |
1745 if (((char *)msg_ga.ga_data)[i] == '\n') | |
1746 ((char *)msg_ga.ga_data)[i] = '\0'; | |
1747 lua_pushlstring(L, msg_ga.ga_data, msg_ga.ga_len); | |
1743 if (!got_int) | 1748 if (!got_int) |
1744 luaV_msg(L); | 1749 luaV_msg(L); |
1750 | |
1751 ga_clear(&msg_ga); | |
1745 return 0; | 1752 return 0; |
1746 } | 1753 } |
1747 | 1754 |
1748 static int | 1755 static int |
1749 luaV_debug(lua_State *L) | 1756 luaV_debug(lua_State *L) |