Navigation Menu

Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
node: provide snprintf implementation on windows
Browse files Browse the repository at this point in the history
_snprintf() doesn't zero-terminate the buffer on overflow.
  • Loading branch information
bnoordhuis committed Mar 31, 2012
1 parent dee8c51 commit a4a04f9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/node_internals.h
Expand Up @@ -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
Expand Down

0 comments on commit a4a04f9

Please sign in to comment.