Skip to content
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

Library/libs/sprintf.c: don't write nul if size == 0 #1158

Closed
wants to merge 1 commit into from

Conversation

six809
Copy link

@six809 six809 commented Feb 6, 2025

In snprintf() and vsnprintf().

Allows use of *snprintf(NULL, 0, ...) without segfault.

In snprintf() and vsnprintf().

Allows use of *snprintf(NULL, 0, ...) without segfault.
@EtchedPixels EtchedPixels added the bug Misbehaviour rather than feature request label Feb 6, 2025
@EtchedPixels
Copy link
Owner

Think it's a shade more complicated to fix properly. Will have a look when I have a bit of time.

@EtchedPixels
Copy link
Owner

EtchedPixels commented Feb 6, 2025

Think it should if (rv < size) so that it does the right thing for overrunning strings too ?

@six809
Copy link
Author

six809 commented Feb 6, 2025 via email

@EtchedPixels
Copy link
Owner

will take a look in detail - also if bufpos is ending up stuck on the last char whether the length return is right in that case and stuff..

@six809
Copy link
Author

six809 commented Feb 6, 2025 via email

@EtchedPixels
Copy link
Owner

Think we need to check size == 0 at the start of the snprintf routines, and pass size - 1 down for the other cases

commit 6b8aca7

@six809 six809 closed this Feb 7, 2025
@six809 six809 deleted the fix-snprintf branch February 7, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Misbehaviour rather than feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants