From 8bb05ac73a5b448b339ce0bc8d396c82c459b47f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 21:33:32 +0200 Subject: Merging upstream version 2.40. Signed-off-by: Daniel Baumann --- lib/mbsedit.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib/mbsedit.c') diff --git a/lib/mbsedit.c b/lib/mbsedit.c index ecfa9f4..9cf4f0f 100644 --- a/lib/mbsedit.c +++ b/lib/mbsedit.c @@ -157,13 +157,14 @@ static size_t mbs_insert(char *str, wint_t c, size_t *ncells) #ifdef HAVE_WIDECHAR wchar_t wc = (wchar_t) c; - char in_buf[MB_CUR_MAX]; + in = malloc(MB_CUR_MAX); + if (!in) + return -1; - n = wctomb(in_buf, wc); + n = wctomb(in, wc); if (n == (size_t) -1) - return n; + goto out; *ncells = wcwidth(wc); - in = in_buf; #else *ncells = 1; in = (char *) &c; @@ -173,6 +174,10 @@ static size_t mbs_insert(char *str, wint_t c, size_t *ncells) memmove(str + n, str, bytes); memcpy(str, in, n); str[bytes + n] = '\0'; +out: +#ifdef HAVE_WIDECHAR + free(in); +#endif return n; } -- cgit v1.2.3