Patch 8.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)
Files: src/if_lua.c, src/misc2.c, src/proto/misc2.pro
*** ../vim-8.2.3243/src/if_lua.c 2021-07-28 21:48:55.841029431 +0200
--- src/if_lua.c 2021-07-29 20:21:17.070130835 +0200
***************
*** 1720,1730 ****
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);
lua_getglobal(L, "tostring");
for (i = 1; i <= n; i++)
{
--- 1720,1731 ----
static int
luaV_print(lua_State *L)
{
! 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,1747 ****
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);
lua_pop(L, 1);
}
! luaL_pushresult(&b);
if (!got_int)
luaV_msg(L);
return 0;
}
--- 1736,1754 ----
if (s == NULL)
return luaL_error(L, "cannot convert to string");
if (i > 1)
! ga_append(&msg_ga, ' '); // use space instead of tab
! ga_concat_len(&msg_ga, (char_u *)s, l);
lua_pop(L, 1);
}
! // 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;
}
*** ../vim-8.2.3243/src/misc2.c 2021-07-27 21:17:28.483675842 +0200
--- src/misc2.c 2021-07-29 20:16:52.722766250 +0200
***************
*** 1566,1571 ****
--- 1566,1587 ----
}
/*
+ * Concatenate 'len' bytes from string 's' to a growarray.
+ * When "s" is NULL does not do anything.
+ */
+ void
+ ga_concat_len(garray_T *gap, char_u *s, size_t len)
+ {
+ if (s == NULL || *s == NUL)
+ return;
+ if (ga_grow(gap, len) == OK)
+ {
+ mch_memmove((char *)gap->ga_data + gap->ga_len, s, (size_t)len);
+ gap->ga_len += len;
+ }
+ }
+
+ /*
* Append one byte to a growarray which contains bytes.
*/
void
*** ../vim-8.2.3243/src/proto/misc2.pro 2021-07-27 21:17:28.483675842 +0200
--- src/proto/misc2.pro 2021-07-29 20:16:52.722766250 +0200
***************
*** 45,50 ****
--- 45,51 ----
char_u *ga_concat_strings(garray_T *gap, char *sep);
int ga_add_string(garray_T *gap, char_u *p);
void ga_concat(garray_T *gap, char_u *s);
+ void ga_concat_len(garray_T *gap, char_u *s, size_t len);
void ga_append(garray_T *gap, int c);
void append_ga_line(garray_T *gap);
int simplify_key(int key, int *modifiers);
*** ../vim-8.2.3243/src/version.c 2021-07-29 19:18:29.587186625 +0200
--- src/version.c 2021-07-29 20:18:40.038508094 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3244,
/**/
--
"Time flies like an arrow". So I put an arrow on my desk, now
awaiting one of these time flies showing up.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202107291822.16TIMmfr2211222%40masaka.moolenaar.net.