NetBSD Problem Report #52282

From perseant@NetBSD.org  Wed Jun  7 22:47:27 2017
Return-Path: <perseant@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id B76667A283
	for <gnats-bugs@gnats.NetBSD.org>; Wed,  7 Jun 2017 22:47:27 +0000 (UTC)
Message-Id: <20170607224625.0B5297A2A6@mollari.NetBSD.org>
Date: Wed,  7 Jun 2017 22:46:25 +0000 (UTC)
From: perseant@NetBSD.org
Reply-To: perseant@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: printf(3) does not correctly interpret C/POSIX locale for %'d, %'f
X-Send-Pr-Version: 3.95

>Number:         52282
>Category:       standards
>Synopsis:       printf(3) does not correctly interpret C/POSIX locale for %'d, %'f
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    standards-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 07 22:50:00 +0000 2017
>Closed-Date:    Mon Jul 10 23:01:27 +0000 2017
>Last-Modified:  Wed Mar 14 18:40:00 +0000 2018
>Originator:     Konrad Schroder
>Release:        NetBSD-current 20170606
>Organization:
Happy Hopeless Hacker House
>Environment:
System: NetBSD mollari.NetBSD.org 7.1_RC2 NetBSD 7.1_RC2 (amd64-DOMU_SERVER) #2:
 Sun Mar 5 17:25:39 UTC 2017 spz@franklin.NetBSD.org:/home/netbsd/7/amd64/obj/sy
s/arch/amd64/compile/amd64-DOMU_SERVER amd64
Architecture: x86_64
Machine: amd64
>Description:
        IEEE Std 1003.1-2008 7.3.4 defines the POSIX locale to have
        thousands separator as "", with no grouping, but printf(3) 
        interprets this to mean "," and groupings of three.
>How-To-Repeat:
#include <stdio.h>
#include <locale.h>

int main (int argc, char **argv)
{
        setlocale(LC_NUMERIC, "POSIX");
        printf("%'f\n", 1234567.89);
}

The expected output is "1234567.890000" but the actual output is "1,234,567.890000".
>Fix:

Index: lib/libc/stdio/vfwprintf.c
===================================================================
RCS file: /cvsroot/src/lib/libc/stdio/vfwprintf.c,v
retrieving revision 1.34
diff -u -r1.34 vfwprintf.c
--- lib/libc/stdio/vfwprintf.c	20 Jan 2014 14:11:03 -0000	1.34
+++ lib/libc/stdio/vfwprintf.c	7 Jun 2017 22:38:51 -0000
@@ -923,15 +923,15 @@
 			sign = '+';
 			goto rflag;
 		case '\'':
-			flags |= GROUPING;
 			thousands_sep = *(localeconv_l(loc)->thousands_sep);
 			grouping = localeconv_l(loc)->grouping;
-			/* If the locale doesn't define the above, use sane
-			 * defaults - otherwise silly things happen! */
-			if (thousands_sep == 0)
-				thousands_sep = ',';
-			if (!grouping || !*grouping)
-				grouping = "\3";
+			/* Use grouping if defined by locale */
+			if (thousands_sep && grouping && *grouping)
+				flags |= GROUPING;
+			else {
+				thousands_sep = '\0';
+				grouping = "";
+			}
 			goto rflag;
 		case '.':
 			if ((ch = *fmt++) == '*') {

>Release-Note:

>Audit-Trail:
From: "Konrad Schroder" <perseant@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52282 CVS commit: src/tests/lib/libc/locale
Date: Wed, 7 Jun 2017 22:59:42 +0000

 Module Name:	src
 Committed By:	perseant
 Date:		Wed Jun  7 22:59:42 UTC 2017

 Modified Files:
 	src/tests/lib/libc/locale: t_sprintf.c

 Log Message:
 Change t_sprintf to an expected failure, since we don't respect the empty
 thousands separator of the C/POSIX locale (PR standards/52282).


 To generate a diff of this commit:
 cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/locale/t_sprintf.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Konrad Schroder" <perseant@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52282 CVS commit: src/lib/libc/stdio
Date: Mon, 10 Jul 2017 22:49:41 +0000

 Module Name:	src
 Committed By:	perseant
 Date:		Mon Jul 10 22:49:40 UTC 2017

 Modified Files:
 	src/lib/libc/stdio: vfwprintf.c

 Log Message:
 Do not use thousands grouping when none is specified by the locale.
 Fixes PR standards/52282.


 To generate a diff of this commit:
 cvs rdiff -u -r1.34 -r1.35 src/lib/libc/stdio/vfwprintf.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: perseant@NetBSD.org
State-Changed-When: Mon, 10 Jul 2017 23:01:27 +0000
State-Changed-Why:
Committed fix in lib/libc/stdio/vfwprintf.c rev 1.35.


From: "Konrad Schroder" <perseant@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52282 CVS commit: src/lib/libc/stdio
Date: Tue, 11 Jul 2017 19:36:38 +0000

 Module Name:	src
 Committed By:	perseant
 Date:		Tue Jul 11 19:36:38 UTC 2017

 Modified Files:
 	src/lib/libc/stdio: vfwprintf.c

 Log Message:
 A more correct fix for PR standards/52282.


 To generate a diff of this commit:
 cvs rdiff -u -r1.35 -r1.36 src/lib/libc/stdio/vfwprintf.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Manuel Bouyer" <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52282 CVS commit: [netbsd-8] src
Date: Wed, 14 Mar 2018 18:37:00 +0000

 Module Name:	src
 Committed By:	bouyer
 Date:		Wed Mar 14 18:37:00 UTC 2018

 Modified Files:
 	src/lib/libc/stdio [netbsd-8]: vfwprintf.c
 	src/tests/lib/libc/locale [netbsd-8]: t_sprintf.c

 Log Message:
 Pull up following revision(s) (requested by martin in ticket #630):
 	lib/libc/stdio/vfwprintf.c: revision 1.35
 	lib/libc/stdio/vfwprintf.c: revision 1.36
 	tests/lib/libc/locale/t_sprintf.c: revision 1.2
 Change t_sprintf to an expected failure, since we don't respect the empty
 thousands separator of the C/POSIX locale (PR standards/52282).
 Do not use thousands grouping when none is specified by the locale.
 Fixes PR standards/52282.
 A more correct fix for PR standards/52282.


 To generate a diff of this commit:
 cvs rdiff -u -r1.34 -r1.34.18.1 src/lib/libc/stdio/vfwprintf.c
 cvs rdiff -u -r1.1 -r1.1.2.1 src/tests/lib/libc/locale/t_sprintf.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.