mirror of
https://github.com/git/git.git
synced 2026-03-13 10:23:30 +01:00
snprintf replacement: Make sure the result is NUL terminated.
On Windows, if the resulting string fits exactly in the provided buffer, but not the terminating NUL, then the return value of the system's vsnprintf is the number of characters written. But since we had reserved an extra byte anyway, we only need to make sure that the result is NUL terminated. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
This commit is contained in:
@@ -16,8 +16,11 @@ int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap)
|
||||
int ret;
|
||||
|
||||
ret = vsnprintf(str, maxsize-SNPRINTF_SIZE_CORR, format, ap);
|
||||
if (ret != -1)
|
||||
if (ret != -1) {
|
||||
/* Windows does not NUL-terminate if result fits exactly */
|
||||
str[ret] = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
s = NULL;
|
||||
if (maxsize < 128)
|
||||
|
||||
Reference in New Issue
Block a user