Date: 2024apr30
Product: Microsoft Visual Studio
Language: C/C++
Language: english
Q. MSVC: _snprintf doesn't NUL-terminate causing corruption
A. Basically _snprintf() became unsafe so use snprintf()
MSDN says:
Beginning with the UCRT in Visual Studio 2015 and Windows 10,
snprintf is no longer identical to _snprintf.
The snprintf behavior is now C99 standard conformant. The difference
is that if you run out of buffer, snprintf
null-terminates the end of the buffer and returns the number of
characters that would have been required whereas _snprintf doesn't
null-terminate the buffer and returns -1.
It goes on to say:
Also, snprintf() includes one more character in the output because
it doesn't null-terminate the buffer. WRONG
I believe that's incorrect - it should say "_snprintf() includes".
I prefer to say NUL-terminated because its the NUL character and
not the NULL pointer at the end of the string.
https://www.google.com/search?q=man+ascii