[prev in list] [next in list] [prev in thread] [next in thread]
List: netbsd-bugs
Subject: standards/53563: printf(1) %x (etc) does not allow negative args
From: kre () munnari ! OZ ! AU
Date: 2018-08-31 1:15:00
Message-ID: 20180831011500.D52247A167 () mollari ! NetBSD ! org
[Download RAW message or body]
> 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: open
> Class: sw-bug
> Submitter-Id: net
> Arrival-Date: Fri Aug 31 01:15:00 +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.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic