From 482d9590b54308e7b2f83cdf4180426c38444894 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 1 Feb 2016 14:52:34 +0100 Subject: Don't use unsafe _snprintf on MSVC older than 2015. Wrap the unsafe _snprintf to ensure that the string is null-terminated even on overflow. --- include/mupdf/fitz/system.h | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/mupdf/fitz/system.h b/include/mupdf/fitz/system.h index aeb5686c..abc3b9b7 100644 --- a/include/mupdf/fitz/system.h +++ b/include/mupdf/fitz/system.h @@ -112,11 +112,32 @@ struct timeval; struct timezone; int gettimeofday(struct timeval *tv, struct timezone *tz); -#define snprintf _snprintf -#if _MSC_VER < 1800 +#if _MSC_VER < 1900 /* MSVC 2015 */ +#define snprintf msvc_snprintf +#define vsnprintf msvc_vsnprintf +static int msvc_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) +{ + int n; + n = _vsnprintf(str, size, fmt, ap); + str[size-1] = 0; + return n; +} +static int msvc_snprintf(char *str, size_t size, const char *fmt, ...) +{ + int n; + va_list ap; + va_start(ap, fmt); + n = msvc_vsnprintf(str, size, fmt, ap); + va_end(ap); + return n; +} +#endif + +#if _MSC_VER < 1700 /* MSVC 2012 */ #define isnan(x) _isnan(x) #define isinf(x) (!_finite(x)) #endif + #define hypotf _hypotf FILE *fz_fopen_utf8(const char *name, const char *mode); -- cgit v1.2.3