From: Bruno Haible Date: Sat, 28 Jan 2023 17:17:17 +0000 (+0100) Subject: vasnprintf-posix: Fix negative width handling for %ls directive. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=3d8ec444d9a0e95d2d7b16dc67a7e27c3169e83d;p=gnulib.git vasnprintf-posix: Fix negative width handling for %ls directive. Reported by clang via Po Lu . * lib/vasnprintf.c (VASNPRINTF): In the code for %ls in vasnprintf and for %s in vasnwprintf, test for the FLAG_LEFT bit in the flags variable. --- diff --git a/ChangeLog b/ChangeLog index a892621b40..207dd0f003 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-01-28 Bruno Haible + + vasnprintf-posix: Fix negative width handling for %ls directive. + Reported by clang via Po Lu . + * lib/vasnprintf.c (VASNPRINTF): In the code for %ls in vasnprintf and + for %s in vasnwprintf, test for the FLAG_LEFT bit in the flags variable. + 2023-01-28 Bruno Haible Avoid clang warnings regarding [[__nodiscard__]]. diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 277c39e3e0..5ab8edbab7 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -2551,7 +2551,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, characters = 0; } - if (characters < width && !(dp->flags & FLAG_LEFT)) + if (characters < width && !(flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); @@ -2612,7 +2612,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, } } - if (characters < width && (dp->flags & FLAG_LEFT)) + if (characters < width && (flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); @@ -2768,7 +2768,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, /* w doesn't matter. */ w = 0; - if (w < width && !(dp->flags & FLAG_LEFT)) + if (w < width && !(flags & FLAG_LEFT)) { size_t n = width - w; ENSURE_ALLOCATION (xsum (length, n)); @@ -2836,7 +2836,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, length += tmpdst_len; # endif - if (w < width && (dp->flags & FLAG_LEFT)) + if (w < width && (flags & FLAG_LEFT)) { size_t n = width - w; ENSURE_ALLOCATION (xsum (length, n));