NetBSD Problem Report #53563
From kre@munnari.OZ.AU Fri Aug 31 01:12:34 2018
Return-Path: <kre@munnari.OZ.AU>
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 "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 3CF897A167
for <gnats-bugs@gnats.NetBSD.org>; Fri, 31 Aug 2018 01:12:34 +0000 (UTC)
Message-Id: <201808310112.w7V1C1SM016011@jinx.noi.kre.to>
Date: Fri, 31 Aug 2018 08:12:01 +0700 (+07)
From: kre@munnari.OZ.AU
To: gnats-bugs@NetBSD.org
Subject: printf(1) %x (etc) does not allow negative args
X-Send-Pr-Version: 3.95
>Number: 53563
>Category: standards
>Synopsis: printf(1) %x (etc) does not allow negative args
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: standards-manager
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Aug 31 01:15:00 +0000 2018
>Closed-Date: Sat Sep 01 08:04:26 +0000 2018
>Last-Modified: Sat Sep 01 08:04:26 +0000 2018
>Originator: Robert Elz
>Release: NetBSD 8.99.24
>Organization:
>Environment:
System: NetBSD jinx.noi.kre.to 8.99.24 NetBSD 8.99.24 (GENERIC) #0: Mon Aug 27 01:30:06 ICT 2018 kre@onyx.coe.psu.ac.th:/usr/obj/testing/amd64/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
After stuff about %b %c and %s treating the arg as a string, and
all the floating formats (if supported, they're optional) sending
the arg through strtod() ...
POSIX sayeth:
Otherwise, they shall be evaluated as unsuffixed C integer
constants, as described by the ISO C standard, with the
following extensions:
+ A leading <plus-sign> or <hyphen-minus> shall be allowed.
+ [...]
Yet for our printf(1) ...
jinx$ /usr/bin/printf '%x\n' -1
printf: -1: expected positive numeric value
0
The %x (and %X obviously, and %o, %u, maybe something else)
convert the arg as an unsigned integer, just like using
printf(3)
printf("%x\n", (unsigned)-1);
They're not supposed to reject it. The printf's built into
bash, ksh93, the FreeBSD shell, yash, dash, all allow it.
>How-To-Repeat:
As above.
>Fix:
Haven't done it yet, but I believe the solution is simply
to delete the getuintmax() function, and use getintmax()
(casting the result when needed) everywhere getuintmax()
is currently used.
>Release-Note:
>Audit-Trail:
From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/53563 CVS commit: src/usr.bin/printf
Date: Fri, 31 Aug 2018 17:27:35 +0000
Module Name: src
Committed By: kre
Date: Fri Aug 31 17:27:35 UTC 2018
Modified Files:
src/usr.bin/printf: printf.1 printf.c
Log Message:
PR standards/53563
POSIX requires that signed numbers (strings preceded by '+' or '-')
be allowed as inputs to all of the integer format conversions, including
those which treat the data as unsigned.
Hence we do not need a variant function whose only difference from its
companion is to reject strings starting with '-' - instead we use
the primary function (getintmax()) for everything and remove getuintmax().
Minor update to the man page to indicate that the arg to all of the
integer conversions (diouxX) must be an integer constant (with an
optional sign) and to make it blatantly clear that %o is octal and
%u is unsigned decimal (for some reason those weren't explicitly stated
unlike d i x and X). Delete "respectively", it is not needed (and does
not really apply).
XXX pullup -8
To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/printf/printf.1
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/printf/printf.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->needs-pullups
State-Changed-By: kre@NetBSD.org
State-Changed-When: Fri, 31 Aug 2018 17:35:10 +0000
State-Changed-Why:
Fix has been committed to HEAD, needs pullup to -8
State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: kre@NetBSD.org
State-Changed-When: Sat, 01 Sep 2018 00:46:53 +0000
State-Changed-Why:
pullup-8 #1002
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/53563 CVS commit: [netbsd-8] src/usr.bin/printf
Date: Sat, 1 Sep 2018 06:27:12 +0000
Module Name: src
Committed By: martin
Date: Sat Sep 1 06:27:12 UTC 2018
Modified Files:
src/usr.bin/printf [netbsd-8]: printf.1
Log Message:
Pull up following revision(s) (requested by kre in ticket #1002):
usr.bin/printf/printf.1: revision 1.31 (via patch)
usr.bin/printf/printf.c: revision 1.43 (via patch)
PR standards/53563
POSIX requires that signed numbers (strings preceded by '+' or '-')
be allowed as inputs to all of the integer format conversions, including
those which treat the data as unsigned.
Hence we do not need a variant function whose only difference from its
companion is to reject strings starting with '-' - instead we use
the primary function (getintmax()) for everything and remove getuintmax().
Minor update to the man page to indicate that the arg to all of the
integer conversions (diouxX) must be an integer constant (with an
optional sign) and to make it blatantly clear that %o is octal and
%u is unsigned decimal (for some reason those weren't explicitly stated
unlike d i x and X). Delete "respectively", it is not needed (and does
not really apply).
XXX pullup -8
To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.25.16.1 src/usr.bin/printf/printf.1
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/53563 CVS commit: [netbsd-8] src/usr.bin/printf
Date: Sat, 1 Sep 2018 06:28:23 +0000
Module Name: src
Committed By: martin
Date: Sat Sep 1 06:28:23 UTC 2018
Modified Files:
src/usr.bin/printf [netbsd-8]: printf.c
Log Message:
Pull up following revision(s) (requested by kre in ticket #1002):
usr.bin/printf/printf.1: revision 1.31 (via patch)
usr.bin/printf/printf.c: revision 1.43
PR standards/53563
POSIX requires that signed numbers (strings preceded by '+' or '-')
be allowed as inputs to all of the integer format conversions, including
those which treat the data as unsigned.
Hence we do not need a variant function whose only difference from its
companion is to reject strings starting with '-' - instead we use
the primary function (getintmax()) for everything and remove getuintmax().
Minor update to the man page to indicate that the arg to all of the
integer conversions (diouxX) must be an integer constant (with an
optional sign) and to make it blatantly clear that %o is octal and
%u is unsigned decimal (for some reason those weren't explicitly stated
unlike d i x and X). Delete "respectively", it is not needed (and does
not really apply).
XXX pullup -8
To generate a diff of this commit:
cvs rdiff -u -r1.37.8.1 -r1.37.8.2 src/usr.bin/printf/printf.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: pending-pullups->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Sat, 01 Sep 2018 08:04:26 +0000
State-Changed-Why:
Pullups completed. Thanks.
>Unformatted:
(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.