-
-
Save bnoordhuis/610fec20e4acba93053a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/node_internals.h b/src/node_internals.h | |
index 0646727..9998c1e 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 <stdarg.h> | |
+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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment