stb_sprintf gcc warning when using -Wextra
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 60/100
Research direction
The warning comes from the ?: expression passed to stbsp__strlen_limited at line 594 of stb/stb_sprintf.h, inside stbsp_vsprintfcb. Reproduce it by compiling a small program that includes the header with gcc -Wall -Wextra. Done means the -Wsign-compare warning no longer appears under gcc with those flags, and clang still builds cleanly.
Written by the indexing model from the issue text.
Description
Describe the bug
When compiling with gcc.exe (Rev6, Built by MSYS2 project) 13.1.0 using -Wextra, the following error is produced:
./stb/stb_sprintf.h: In function 'stbsp_vsprintfcb':
./stb/stb_sprintf.h:594:51: warning: operand of '?:' changes signedness from 'int' to 'unsigned int' due to unsignedness of other operand [-Wsign-compare]
594 | l = stbsp__strlen_limited(s, (pr >= 0) ? pr : ~0u);
| ^~
To Reproduce
Write a simple "Hello, World" program using stb_sprintf and compile with gcc using -Wall and -Wextra options.
Clang does not produce the warning for the same code and compiler options.
The simple fix is to change line 594 (cast pr):
- l = stbsp__strlen_limited(s, (pr >= 0) ? pr : ~0u);
+ l = stbsp__strlen_limited(s, (pr >= 0) ? (stbsp__uint32)pr : ~0u);
- 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
-
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