-
Notifications
You must be signed in to change notification settings - Fork 1.6k
stacktrace.cpp: Fix snprintf() usage
#3916
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
stacktrace.cpp: Fix snprintf() usage
#3916
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These constants are shared as snprintf parameter, and resize_and_overwrite parameter. The later appears not to include \0
AlexGuteniev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually there is nothing wrong with the current snprintf usage.
When null terminator does not fit, snprintf still fills other characters, and return the same result.
The null terminator will be set anyway by string::resize_and_overwrite
TLDR: If we want to use |
|
After thinking about this, Casey's suggested pattern appears to be best. I thought about avoiding the |
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
C23 WP N3096 7.23.6.5 "The
snprintffunction"/2:In English,
nshould be the buffer size, INCLUDING room for a null terminator.stacktrace.cppconsistently saidsizeof("meow") - 1, which excludes the null terminator. This was a mistake.So far I haven't seen actual misbehavior caused by this.