On 19/11/2024 16:47, Paul Eggert wrote:
On 2024-11-19 07:10, Pádraig Brady wrote:
I've not got access to a macos system to test currently,
but the attached should address this.
That patch addresses only the empty string, not other strings that
cannot be converted (e.g., a string consisting of a single space). This
turns out to be a longstanding bug in printf. I installed the attached
fancier patch which should address the more-general problem, and which
adds some test cases. I tested this on cfarm104.cfarm.net which is
running macOS 12.6.
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
That's different to bash and dash.
More problematically I think is it's also inconsistent with %s
$ src/printf '%s'
$ src/printf '%s' ''
BTW after we decide the best operation, we should update NEWS.
I had done this locally like:
printf consistently outputs 0 for numeric conversions of empty strings.
Previously on systems like macos, it would have failed with an error.
cheers,
Pádraig