* gl/lib/mbsalign.c (mbsalign): Ensure the temporary destination buffer
is big enough, as it may need to be bigger than the source buffer
in the presence of single byte non printable chars.
* gl/tests/test-mbsalign.c (main): Add a test to trigger the issue.
then create a modified copy of it. */
if (wc_enabled && (conversion || (n_cols > *width)))
{
+ if (conversion)
+ {
+ /* May have increased the size by converting
+ \t to \uFFFD for example. */
+ src_size = wcstombs (NULL, str_wc, 0) + 1;
+ }
newstr = malloc (src_size);
if (newstr == NULL)
{
width = 4; /* cells */
n = mbsalign ("¹²³", dest, 0, &width, MBS_ALIGN_LEFT, 0);
ASSERT (width == 3);
+
+ /* Test case where output is larger than input
+ (as tab converted to multi byte replacement char). */
+ width = 4;
+ n = mbsalign ("t\tés" /* 6 including NUL */ , dest, sizeof dest,
+ &width, MBS_ALIGN_LEFT, 0);
+ ASSERT (n == 7);
}
return 0;