string.c: Alloc space for terminating null wide character.
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 29 Feb 2016 18:26:09 +0000 (19:26 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 13 Mar 2016 17:11:32 +0000 (18:11 +0100)
Should not matter since we already know the number of wide characters
and never look past the allocated buffer. But let's be conservative
here and allocate space for the terminating null wide character.

string.c

index c820bdca3fd1ca37695354aa03024b4d384da765..701448e041cfa9ff86dc1a6cccf37cd088b76c20 100644 (file)
--- a/string.c
+++ b/string.c
@@ -1073,7 +1073,7 @@ __must_check int strwidth(const char *s, size_t *result)
                return -ERRNO_TO_PARA_ERROR(errno);
        if (num_wchars == 0)
                return 0;
-       dest = para_malloc(num_wchars * sizeof(*dest));
+       dest = para_malloc((num_wchars + 1) * sizeof(*dest));
        src = s;
        memset(&state, 0, sizeof(state));
        num_wchars = mbsrtowcs(dest, &src, num_wchars, &state);