From a4a04f932ed99a8195f6d44227b1e89f5b9ea381 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 1 Apr 2012 01:15:17 +0200 Subject: [PATCH] node: provide snprintf implementation on windows _snprintf() doesn't zero-terminate the buffer on overflow. --- src/node_internals.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/node_internals.h b/src/node_internals.h index 0646727e1b..8d073927b8 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -27,7 +27,17 @@ namespace node { #ifdef _WIN32 -# define snprintf _snprintf +// emulate snprintf() on windows, _snprintf() doesn't zero-terminate the buffer +// on overflow... +#include +inline static int snprintf(char* buf, unsigned int len, const char* fmt, ...) { + va_list ap; + va_start(ap, fmt); + int n = _vsprintf_p(buf, len, fmt, ap); + if (len) buf[len - 1] = '\0'; + va_end(ap); + return n; +} #endif #ifndef offset_of