[sprintf] Wrong handling of " " flag for unsigned specifiers
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 68/100
Research direction
The bug is in stb_sprintf.h, where the space flag is parsed around lines 1056-1057 and the STBSP__LEADINGSPACE flag is set. Read how unsigned conversions reuse that flag, then compare the output with the system printf for %- 10u and % 010u. Done means unsigned specifiers ignore the space flag and match the standard output, with the change verified against those two cases.
Written by the indexing model from the issue text.
Description
The standard says:
space If the first character of a signed conversion is not a sign, or if a signed conversion results in no characters, a space is prefixed to the result.
This seems to mean that unsigned specifiers should ignore the ' ' flag. This is what other implementations do.
STB vs standard-conforming:
printf("%- 10u", 1); // " 1 " vs "1 "
printf("% 010u", 1); // " 000000001" vs "0000000001"
Fix: in between lines 1056-1057:
https://github.com/nothings/stb/blob/f0569113c93ad095470c54bf34a17b36646bbbb5/stb_sprintf.h#L1056-L1057
clear the STBSP__LEADINGSPACE flag:
fl &= ~STBSP__LEADINGSPACE;
- Dominant language
- C
- Stars
- 18
- Forks
- 5
- Avg merge
- 1m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nothings/stb_sprintf
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
nothings/stb_sprintf#10 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
nothings/stb_sprintf#8 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nothings/stb_sprintf#5 ·
-
[SECURITY] stbsp_snprintf with count=0 writes null terminator before bufferPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nothings/stb_sprintf#4 ·
-
Difficulty 2/5 Under an hour Newbie friendliness 68/100
nothings/stb_sprintf#17 ·
All issues in nothings/stb_sprintf
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 5 days
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
bug severity: medium
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
AlessandroSangiuliano/Uros#1014 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
OpenXiangShan/NEMU#1314 ·
Maintainers usually reply within 1 day