NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

standards/53563: printf(1) %x (etc) does not allow negative args



>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@localhost:/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.



Home | Main Index | Thread Index | Old Index