Wrong handling of "%#o" #1794
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
Research direction
Start in stb_sprintf.h around line 1029, where the issue identifies the precision check to change. Read the surrounding octal formatting logic and compare its output with the standard for printf("%#.0o", 0). Done means the output is 0 for that case while existing formatting behavior remains intact.
Written by the indexing model from the issue text.
Description
(moved from https://github.com/nothings/stb/issues/1794)
The standard says:
# The result is converted to an "alternative form". For o conversion, it increases the precision, if and only if necessary, to force the first digit of the result to be a zero (if the value and precision are both 0, a single 0 is printed)
STB vs standard-conforming:
printf("%#.0o", 0); // "" vs "0"
Fix: change line 1029
https://github.com/nothings/stb/blob/f0569113c93ad095470c54bf34a17b36646bbbb5/stb_sprintf.h#L1025-L1034
from:
if (pr == 0)
to:
if (pr == 0 && !(f[0] == 'o' && (fl & STBSP__LEADING_0X)))
- 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 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 ·
-
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