Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printf: extra specifiers not evaluated as if 0 supplied #9321

Closed
floam opened this issue Oct 31, 2022 · 5 comments
Closed

printf: extra specifiers not evaluated as if 0 supplied #9321

floam opened this issue Oct 31, 2022 · 5 comments
Labels
bug Something that's not working as intended
Milestone

Comments

@floam
Copy link
Member

floam commented Oct 31, 2022

printf(1) is supposed to have this property:

The format operand shall be reused as often as necessary to satisfy the argument operands. Any extra b, c, or s conversion specifiers shall be evaluated as if a null string argument were supplied; other extra conversion specifications shall be evaluated as if a zero argument were supplied. If the format operand contains no conversion specifications and argument operands are present, the results are unspecified.

Fish doesn't do this, causing this discrepancy:

> ksh -c 'printf "%d %d\n" 1 2 3'
1 2
3 0
> zsh -c 'printf "%d %d\n" 1 2 3'
1 2
3 0
> bash -c 'printf "%d %d\n" 1 2 3'
1 2
3 0
> fish -c 'printf "%d %d\n" 1 2 3'
1 2
3 : Invalid argument
@floam floam added the bug Something that's not working as intended label Oct 31, 2022
@floam floam added this to the fish-future milestone Oct 31, 2022
@faho
Copy link
Member

faho commented Oct 31, 2022

This works for me in both fish 3.5.1 and #9313.

@floam
Copy link
Member Author

floam commented Oct 31, 2022

Huh. It does not work on master, #9313, or 3.5.1 for me.

> /opt/homebrew/Cellar/fish/3.5.1/bin/fish -c 'printf "%d %d\n" 1 2 3'
1 2
3 : Invalid argument

A difference on BSD/macOS perhaps?

@floam
Copy link
Member Author

floam commented Oct 31, 2022

On the other hand, %f works. This is something to do with the errno after std::wcstol but not std::wcstod.

> printf "%f %f\n" 1 1 1
1.000000 1.000000
1.000000 0.000000

@mqudsi
Copy link
Contributor

mqudsi commented Nov 1, 2022

Works for me under Linux, but confirmed broken on FreeBSD. Good candidate for our test suite after it gets fixed.

@floam floam closed this as completed in 1a0d6eb Nov 1, 2022
@floam
Copy link
Member Author

floam commented Nov 1, 2022

@mqudsi yeah. I added a test for this little stinker.

@floam floam modified the milestones: fish-future, fish 3.6.0 Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that's not working as intended
Projects
None yet
Development

No branches or pull requests

3 participants