[sprintf] Wrong handling of "+ " flags
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 62/100
Research direction
The bug is in stbsp__lead_sign() in stb_sprintf.h, around lines 294-307, which checks the negative, space and plus flags in the wrong order. Read that function, then compare its output with a standard printf for the eight %+ 10i, % +10f, %+ 10g and %+ 10a cases in the issue. Done when the plus flag takes precedence over the space flag in every case and the output matches the standard.
Written by the indexing model from the issue text.
Description
The standard says:
If the space and + flags both appear, the space flag is ignored.
STB vs standard-conforming:
printf("%+ 10i", 1); // " 1" vs " +1"
printf("% +10i", 1); // " 1" vs " +1"
printf("%+ 10f", 1.0); // " 1.000000" vs " +1.000000"
printf("% +10f", 1.0); // " 1.000000" vs " +1.000000"
printf("%+ 10g", 1.0); // " 1" vs " +1"
printf("% +10g", 1.0); // " 1" vs " +1"
printf("%+ 10a", 1.0); // " 0x1.000000p+0" vs " +0x1.000000p+0"
printf("% +10a", 1.0); // " 0x1.000000p+0" vs " +0x1.000000p+0"
Fix: the stbsp__lead_sign() function should change the order of its checks: first negative, then plus, then space (now it checks negative, space, plus):
https://github.com/nothings/stb/blob/f0569113c93ad095470c54bf34a17b36646bbbb5/stb_sprintf.h#L294-L307
- 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 1/5 Under an hour Newbie friendliness 68/100
nothings/stb_sprintf#20 ·
All issues in nothings/stb_sprintf
Similar issues
-
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
-
`get_options()` repeats the first byte when hex-encoding octet stringsPossibly taken @rue19 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
OpenPrinting/cups#1830 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
micropython/micropython#20020 ·
Maintainers usually reply within 1 day