From ffa1d09d4774b460bdcde5af5be8b3b30bfe5d29 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 28 Jan 2023 19:39:23 +0100 Subject: [PATCH] unistdio/*printf: Fix negative width handling for %U, %lU, %llU. * lib/vasnprintf.c (VASNPRINTF): In the code for %U, %lU, %llU, test for the FLAG_LEFT bit in the flags variable. --- ChangeLog | 6 ++++++ lib/vasnprintf.c | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 622e4f7ffd..4c8197821e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-01-28 Bruno Haible + + unistdio/*printf: Fix negative width handling for %U, %lU, %llU. + * lib/vasnprintf.c (VASNPRINTF): In the code for %U, %lU, %llU, test for + the FLAG_LEFT bit in the flags variable. + 2023-01-28 Bruno Haible vasnprintf-posix: Fix possible bug with negative width handling for %lc. diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 0e6220ae18..72b8cdbfa6 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -2130,7 +2130,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)); @@ -2175,7 +2175,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, } # endif - if (characters < width && (dp->flags & FLAG_LEFT)) + if (characters < width && (flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); @@ -2232,7 +2232,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)); @@ -2277,7 +2277,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, } # endif - if (characters < width && (dp->flags & FLAG_LEFT)) + if (characters < width && (flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); @@ -2334,7 +2334,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)); @@ -2379,7 +2379,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, } # endif - if (characters < width && (dp->flags & FLAG_LEFT)) + if (characters < width && (flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); -- 2.39.5