diff options
author | Jose Luis Duran <jlduran@gmail.com> | 2022-10-21 19:34:09 +0000 |
---|---|---|
committer | Konstantin Belousov <kib@FreeBSD.org> | 2022-10-25 21:40:17 +0000 |
commit | 34f88528edba44b2703ba8c772bef077eca33dab (patch) | |
tree | 4acdb68597430d5a5b938183b45f1276754a792a /lib/libc | |
parent | 750fe3e6a4619e040c7b0951775698b61290102e (diff) | |
download | src-34f88528edba44b2703ba8c772bef077eca33dab.tar.gz src-34f88528edba44b2703ba8c772bef077eca33dab.zip |
strfmon: Fix formatting of a second fixed-width value
There is a bug when formatting two consecutive values using fixed-widths
and the values need padding. This was because the value of pad_size
was zeroed only every other time.
Format Before After
[%8n] [%8n] [ $123.45] [ $123.45] [ $123.45] [ $123.45]
Reviewed by: kib
PR: 267282
Github PR: #619
MFC after: 1 week
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdlib/strfmon.c | 2 | ||||
-rw-r--r-- | lib/libc/tests/stdlib/strfmon_test.c | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/lib/libc/stdlib/strfmon.c b/lib/libc/stdlib/strfmon.c index d453b7a3943b..c0579f31e821 100644 --- a/lib/libc/stdlib/strfmon.c +++ b/lib/libc/stdlib/strfmon.c @@ -135,7 +135,6 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, fmt = format; asciivalue = NULL; currency_symbol = NULL; - pad_size = 0; while (*fmt) { /* pass nonformating characters AS IS */ @@ -155,6 +154,7 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, /* set up initial values */ flags = (NEED_GROUPING|LOCALE_POSN); pad_char = ' '; /* padding character is "space" */ + pad_size = 0; /* no padding initially */ left_prec = -1; /* no left precision specified */ right_prec = -1; /* no right precision specified */ width = -1; /* no width specified */ diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c index 664d1811dc46..d8e4f478547a 100644 --- a/lib/libc/tests/stdlib/strfmon_test.c +++ b/lib/libc/tests/stdlib/strfmon_test.c @@ -74,7 +74,7 @@ ATF_TC_BODY(strfmon_examples, tc) const char *expected; } tests[] = { { "%n", "[$123.45] [-$123.45] [$3,456.78]" }, - { "%11n", "[ $123.45] [ -$123.45] [ $3,456.78]" }, /* XXX */ + { "%11n", "[ $123.45] [ -$123.45] [ $3,456.78]" }, { "%#5n", "[ $ 123.45] [-$ 123.45] [ $ 3,456.78]" }, { "%=*#5n", "[ $***123.45] [-$***123.45] [ $*3,456.78]" }, { "%=0#5n", "[ $000123.45] [-$000123.45] [ $03,456.78]" }, |