diff --git a/test/task.h b/test/task.h index 6f96a4ff..e050dca0 100644 --- a/test/task.h +++ b/test/task.h @@ -153,4 +153,32 @@ enum test_status { return TEST_SKIP; \ } while (0) +#ifdef _WIN32 + +#include + +/* Emulate snprintf() on Windows, _snprintf() doesn't zero-terminate the buffer + * on overflow... + */ +static int snprintf(char* buf, size_t len, const char* fmt, ...) { + va_list ap; + int n; + + va_start(ap, fmt); + n = _vsprintf_p(buf, len, fmt, ap); + va_end(ap); + + /* It's a sad fact of life that no one ever checks the return value of + * snprintf(). Zero-terminating the buffer hopefully reduces the risk + * of gaping security holes. + */ + if (n < 0) + if (len > 0) + buf[0] = '\0'; + + return n; +} + +#endif + #endif /* TASK_H_ */