GNU bug report logs - #74427
tests/printf/printf-indexed failure on macOS

Previous Next

Package: coreutils;

Reported by: Grisha Levit <grishalevit <at> gmail.com>

Date: Tue, 19 Nov 2024 04:39:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: 74427 <at> debbugs.gnu.org, grishalevit <at> gmail.com
Subject: bug#74427: tests/printf/printf-indexed failure on macOS
Date: Tue, 19 Nov 2024 12:02:41 -0800
On 2024-11-19 09:53, Pádraig Brady wrote:
> Do we really want to treat NUL and NULL strings differently?
> 
>    $ src/printf '%d\n'
>    0
>    $ src/printf '%d\n' ''
>    printf: ‘’: expected a numeric value
>    0

Both behaviors are required by POSIX, so yes, we want to treat them 
differently. Also, it makes sense to treat '' like ' '; we report an 
error for the latter so we should report it for the former too.


> More problematically I think is it's also inconsistent with %s
> 
>   $ src/printf '%s'
>   $ src/printf '%s' '' 

I don't see a problem there. As per POSIX, missing string arguments are 
treated as empty strings, whereas missing numeric arguments are treated 
as zero.


> That's different to bash and dash.

AIX and Solaris 10 printf do things the right way (i.e., conform to 
POSIX) - not surprising as AIX at least has gone through POSIX 
conformance tests. I expect the GNU divergence from tradition was 
accidental, as it doesn't make sense for printf to treat '' differently 
from other non-numbers.

I filed bug reports for both Bash and Dash; see:

https://lists.gnu.org/r/bug-bash/2024-11/msg00149.html
https://lore.kernel.org/dash/20241119193211.1585716-1-eggert <at> cs.ucla.edu/T/#u


> BTW after we decide the best operation, we should update NEWS. 

Thanks, good point. How about something like the following:

printf now diagnoses attempts to treat empty strings as numbers, as per 
POSIX. For example, "printf '%d' ''" now issues a diagnostic and fails 
instead of silently succeeding.




This bug report was last modified 239 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.