Skip to content

Use snprintf instead of sprintf #1086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2025
Merged

Conversation

ahans
Copy link
Contributor

@ahans ahans commented Aug 19, 2025

sprintf has been deprecated on macOS and a warning is issued when using it. -Werror turns the warning into an error, consequently tests don't pass on macOS. This fixes this by using snprintf instead.

@ahans ahans force-pushed the ahans/sprintf-fixes-apple-clang branch from 2bf7563 to 6c50449 Compare August 19, 2025 21:14
Copy link
Member

@ryanplusplus ryanplusplus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good once CI is happy

`sprintf` has been deprecated on macOS and a warning is issued when using it.
`-Werror` turns the warning into an error, consequently tests don't pass on
macOS. This fixes this by using `snprintf` instead.
@ahans ahans force-pushed the ahans/sprintf-fixes-apple-clang branch from 6c50449 to 05df667 Compare August 19, 2025 21:19
@ahans
Copy link
Contributor Author

ahans commented Aug 19, 2025

Looks good once CI is happy

Not sure why this works on macOS, it didn't make much sense. One of the rare cases where I tried having Copilot do all the editing. It figured out which files needed some modificiations and also interpreted the error message correctly (we need to replace sprintf with snprintf), but it did a terrible job at figuring out the actual max lengths. Doing it myself from the start would have been quicker ...

@ryanplusplus ryanplusplus merged commit f5b7fe1 into main Aug 19, 2025
4 checks passed
@ryanplusplus ryanplusplus deleted the ahans/sprintf-fixes-apple-clang branch August 19, 2025 21:24
ahans added a commit to ahans/c that referenced this pull request Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants