Replace `sprintf` in `llvm/lib/Support/zOSLibFunctions.cpp`
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
https://github.com/llvm/llvm-project/blob/1a2f45be47ccdfbaa206ca6b486f91c205d578f6/llvm/lib/Support/zOSLibFunctions.cpp#L66-L73
`sprintf` is generally unsafe, so we should probably replace this with `snprintf`. If `snprintf` is not available, we could also manually implement `%d` if we do not need to worry about locales (this may also improve performance and reduce the chances of race conditions).
Otherwise, the `char buf[256]` should be large enough to not cause any issues.
***
Regardless of what we do, I think it may also be good to set `msg[sizeof(msg) - 1] = '\0'`. Just in case a `nul` terminator is overwritten due to race conditions.
Contributor guide
Research direction
Open llvm/lib/Support/zOSLibFunctions.cpp and inspect lines 66-73, including how the buffer is formatted and whether snprintf is available on z/OS. Replace the unsafe formatting while preserving the expected integer output and ensuring the buffer remains NUL-terminated; verify the surrounding code still builds and behaves as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 76/100