Variable-length-arrays are susceptible to security issues, avoid them.
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
#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;
memmove(str + n, str, bytes);
memcpy(str, in, n);
str[bytes + n] = '\0';
+out:
+#ifdef HAVE_WIDECHAR
+ free(in);
+#endif
return n;
}