summaryrefslogtreecommitdiff
path: root/gl/lib/mbsalign.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2010-03-19 21:40:05 +0000
committerPádraig Brady <P@draigBrady.com>2010-03-19 21:40:05 +0000
commitc872a1d8a51617c2ec76423da6f76ef2208f30d9 (patch)
tree379df526baf20883e9497bfe574ec9b051d48c88 /gl/lib/mbsalign.c
parentdfe0d336a00940c8e13c24b6d5d7485a2d7310b0 (diff)
downloadcoreutils-c872a1d8a51617c2ec76423da6f76ef2208f30d9.tar.xz
maint: mbsalign: fix an edge case where we truncate too much
* 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.
Diffstat (limited to 'gl/lib/mbsalign.c')
-rw-r--r--gl/lib/mbsalign.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/gl/lib/mbsalign.c b/gl/lib/mbsalign.c
index 5b55ec2d0..b92fe8f79 100644
--- a/gl/lib/mbsalign.c
+++ b/gl/lib/mbsalign.c
@@ -178,6 +178,12 @@ mbsalign (const char *src, char *dest, size_t dest_size,
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)
{