mirror of https://github.com/nodejs/node.git
node: provide snprintf implementation on windows
_snprintf() doesn't zero-terminate the buffer on overflow.pull/24503/head
parent
dee8c51547
commit
a4a04f932e
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue