[PATCH 03/17] Define SNPRINTF_SIZE_CORR=1 for Microsoft Visual C++
- From
Marius Storm-Olsen <mstormo@gmail.com>
- Date
- Sep 14, 2009, 13:11 UTC
- Message-ID
- <e2eff51e8d956e7cf854bea9fb9f10491f6d6543.1252925290.git.mstormo@gmail.com>
- In-Reply-To
- <7786dfa1b74b5c4974bcf2018d3991c215a9466f.1252925290.git.mstormo@gmail.com>
From: Frank Li <lznuaa@gmail.com>
Microsoft's vsnprintf function does not add NUL at the end of the buffer, if the result fits the buffer size exactly.
Signed-off-by: Frank Li <lznuaa@gmail.com> Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com> --- compat/snprintf.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/compat/snprintf.c b/compat/snprintf.c index 4d07087..e1e0e75 100644 --- a/compat/snprintf.c +++ b/compat/snprintf.c @@ -2,12 +2,14 @@ /* * The size parameter specifies the available space, i.e. includes - * the trailing NUL byte; but Windows's vsnprintf expects the - * number of characters to write, and does not necessarily write the - * trailing NUL. + * the trailing NUL byte; but Windows's vsnprintf uses the entire + * buffer and avoids the trailing NUL, should the buffer be exactly + * big enough for the result. Defining SNPRINTF_SIZE_CORR to 1 will + * therefore remove 1 byte from the reported buffer size, so we + * always have room for a trailing NUL byte. */ #ifndef SNPRINTF_SIZE_CORR -#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 4 +#if defined(WIN32) && (!defined(__GNUC__) || __GNUC__ < 4) #define SNPRINTF_SIZE_CORR 1 #else #define SNPRINTF_SIZE_CORR 0
-- 1.6.2.1.418.g33d56.dirty