Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 03 Dec 2025 02:38:29 +0000
From:      Jose Luis Duran <jlduran@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 1869d604e22d - stable/14 - strfmon: Fix negative sign handling for C locale
Message-ID:  <692fa2a5.2f86a.6c439f47@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/14 has been updated by jlduran:

URL: https://cgit.FreeBSD.org/src/commit/?id=1869d604e22d88c8c7487cd8a547de42847a40be

commit 1869d604e22d88c8c7487cd8a547de42847a40be
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2025-11-26 20:34:56 +0000
Commit:     Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2025-12-03 02:34:33 +0000

    strfmon: Fix negative sign handling for C locale
    
    If the locale's positive_sign and negative_sign values would both be
    returned by localeconv() as empty strings, strfmon() shall behave as if
    the negative_sign value was the string "-".
    
    This occurs with the C locale.  The implementation previously assigned
    "0" to sign_posn (parentheses around the entire string); now it assigns
    it to "1" (sign before the string) when it is undefined (CHAR_MAX).
    
    Austin Group Defect 1199[1] is applied, changing the requirements for
    the '+' and '(' flags.
    
    [1]: https://www.austingroupbugs.net/view.php?id=1199
    
    Reviewed by:    kib
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D53913
    
    (cherry picked from commit cf85e7034ad5640b18a3b68d6b291b7bf89bfc80)
---
 lib/libc/stdlib/strfmon.c            | 2 +-
 lib/libc/tests/stdlib/strfmon_test.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/libc/stdlib/strfmon.c b/lib/libc/stdlib/strfmon.c
index b19d9fc43369..611ac45b9c82 100644
--- a/lib/libc/stdlib/strfmon.c
+++ b/lib/libc/stdlib/strfmon.c
@@ -457,7 +457,7 @@ __setup_vars(int flags, char *cs_precedes, char *sep_by_space, char *sign_posn,
 	if (*sep_by_space == CHAR_MAX)
 		*sep_by_space = 0;
 	if (*sign_posn == CHAR_MAX)
-		*sign_posn = 0;
+		*sign_posn = 1;
 }
 
 static int
diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c
index 165ddcc2ab56..c6c20bd26985 100644
--- a/lib/libc/tests/stdlib/strfmon_test.c
+++ b/lib/libc/tests/stdlib/strfmon_test.c
@@ -205,8 +205,8 @@ ATF_TC_BODY(strfmon_plus_or_parenthesis, tc)
 	    { "%(i", "C", "[123.45] [(123.45)]" },
 	    { "%(n", "en_US.UTF-8", "[$123.45] [($123.45)]" },
 	    { "%(i", "en_US.UTF-8", "[USD123.45] [(USD123.45)]" },
-	    { "%n", "C", "[123.45] [(123.45)]" }, /* XXX */
-	    { "%i", "C", "[123.45] [(123.45)]" }, /* XXX */
+	    { "%n", "C", "[123.45] [-123.45]" },
+	    { "%i", "C", "[123.45] [-123.45]" },
 	    { "%n", "en_US.UTF-8", "[$123.45] [-$123.45]" },
 	    { "%i", "en_US.UTF-8", "[USD123.45] [-USD123.45]" },
 	};
@@ -253,7 +253,7 @@ ATF_TC_BODY(strfmon_l, tc)
 		const char *locale;
 		const char *expected;
 	} tests[] = {
-	    { "C", "[ **1234.57 ] [ **1234.57 ]" }, /* XXX */
+	    { "C", "[ **1234.57] [ **1234.57]" },
 	    { "de_DE.UTF-8", "[ **1234,57 €] [ **1.234,57 EUR]" },
 	    { "en_GB.UTF-8", "[ £**1234.57] [ GBP**1,234.57]" },
 	};


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?692fa2a5.2f86a.6c439f47>