summaryrefslogtreecommitdiffstats
path: root/lib/mbsedit.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/mbsedit.c13
1 files changed, 9 insertions, 4 deletions
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;
}