git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 02/12] Define SNPRINTF_SIZE_CORR=1 for Microsoft Visual C++

From
Frank Li <lznuaa@gmail.com>
Date
Aug 19, 2009, 15:52 UTC
Message-ID
<1250697167-5536-2-git-send-email-lznuaa@gmail.com>
In-Reply-To
<1250697167-5536-1-git-send-email-lznuaa@gmail.com>

The Microsoft C runtime's vsnprintf function does not add NUL at the end of the buffer.

Further, Microsoft deprecated vsnprintf in favor of _vsnprintf, so add a #define to that end.

Signed-off-by: Frank Li <lznuaa@gmail.com>
---
 compat/snprintf.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/compat/snprintf.c b/compat/snprintf.c
index 6c0fb05..47b2b8a 100644
--- a/compat/snprintf.c
+++ b/compat/snprintf.c
@@ -6,7 +6,7 @@
  * number of characters to write without the trailing NUL.
  */
 #ifndef SNPRINTF_SIZE_CORR
-#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 4
+#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 4 || defined(_MSC_VER)
 #define SNPRINTF_SIZE_CORR 1
 #else
 #define SNPRINTF_SIZE_CORR 0
@@ -14,6 +14,11 @@
 #endif
 
 #undef vsnprintf
+
+#if defined(_MSC_VER)
+#define vsnprintf _vsnprintf
+#endif
+
 int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap)
 {
 	char *s;
-- 
1.6.4.msysgit.0
Previous: Frank LiNext: Frank Li
Message 2 of 12 in “Avoid declaration after instruction”
  1. 01/12 Avoid declaration after instructionFrank Li, Aug 19, 2009
  2. 02/12 Define SNPRINTF_SIZE_CORR=1 for Microsoft Visual C++Frank Li, Aug 19, 2009
  3. 03/12 Using macro WIN32 replace __MINGW32_ at Windows special handler The code which is conditional on MinGW32 is actually conditional on Windows. Use WIN32 macro will share both MINGW32 and MSVC environment.Frank Li, Aug 19, 2009
  4. 04/12 mingw.c: Use the O_BINARY flag to open filesFrank Li, Aug 19, 2009
  5. 05/12 Place __stdcall between return value and function nameFrank Li, Aug 19, 2009
  6. 06/12 Add _MSC_VER in porting head file git-compat-util.hFrank Li, Aug 19, 2009
  7. 07/12 Add Unix header files to build git at MSVC.Frank Li, Aug 19, 2009
  8. 08/12 Add MSVC porting files.Frank Li, Aug 19, 2009
  9. 09/12 Don't include windows.h at winansi.c at MSVC buildFrank Li, Aug 19, 2009
  10. 10/12 Fix errcode have defined as int at MSVCFrank Li, Aug 19, 2009
  11. 11/12 Add MSVC Project fileFrank Li, Aug 19, 2009
  12. Erik Faye-LundAug 19, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.