+2024-06-19 Bruno Haible <bruno@clisp.org>
+
+ vasnwprintf: Optimize handling of %c directive.
+ * lib/vasnprintf.c (VASNPRINTF): Use a single ENSURE_ALLOCATION instead
+ of two.
+
2024-06-19 Bruno Haible <bruno@clisp.org>
u*-vasnprintf: Fix a rare memory leak.
/* Invalid or incomplete multibyte character. */
goto fail_with_EILSEQ;
- if (1 < width && !(flags & FLAG_LEFT))
- {
- size_t n = width - 1;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_SET (result + length, ' ', n);
- length += n;
- }
+ {
+ size_t total = (1 < width ? width : 1);
+ ENSURE_ALLOCATION (xsum (length, total));
+
+ if (1 < width && !(flags & FLAG_LEFT))
+ {
+ size_t n = width - 1;
+ DCHAR_SET (result + length, ' ', n);
+ length += n;
+ }
- ENSURE_ALLOCATION (xsum (length, 1));
- result[length++] = wc;
+ result[length++] = wc;
- if (1 < width && (flags & FLAG_LEFT))
- {
- size_t n = width - 1;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_SET (result + length, ' ', n);
- length += n;
- }
+ if (1 < width && (flags & FLAG_LEFT))
+ {
+ size_t n = width - 1;
+ DCHAR_SET (result + length, ' ', n);
+ length += n;
+ }
+ }
}
}
#endif