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=53f851bf25cddf1ad3a2e9e332c1b0e626e57a56;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 b9ca4abe35..bf7aed0812 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 6eb33c8740..6fc1acbe5b 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -1,5 +1,5 @@ /* vsprintf with automatic memory allocation. - Copyright (C) 1999, 2002-2022 Free Software Foundation, Inc. + Copyright (C) 1999, 2002-2023 Free Software Foundation, Inc. This file is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -2552,7 +2552,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)); @@ -2613,7 +2613,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)); @@ -2769,7 +2769,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)); @@ -2837,7 +2837,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));