]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Use _snprintf for snprinf in Microsoft C.
authorMark Adler <madler@alumni.caltech.edu>
Sun, 3 Jun 2012 19:45:55 +0000 (12:45 -0700)
committerMark Adler <madler@alumni.caltech.edu>
Sun, 3 Jun 2012 19:45:55 +0000 (12:45 -0700)
More than a decade later, Microsoft C does not support the C99
standard.  It's good that _snprintf has a different name, since it
does not guarantee that the result is null terminated, as does
snprintf.  However where _snprintf is used under Microsoft C, the
destination string is assured to be long enough, so this will not
be a problem.  This occurs in two places, both in gzlib.c.  Where
sprintf functionality is needed by gzprintf, vsnprintf is used in
the case of Microsoft C.

gzguts.h

index ee3f281aa5713659c007fed390009490afb60c15..68d135b47e1bf4d2bdd986a450737f3326c4134a 100644 (file)
--- a/gzguts.h
+++ b/gzguts.h
 #  endif
 #endif
 
+/* unlike snprintf (which is required in C99, yet still not supported by
+   Microsoft more than a decade later!), _snprintf does not guarantee null
+   termination of the result -- however this is only used in gzlib.c where
+   the result is assured to fit in the space provided */
+#ifdef _MSC_VER
+#  define snprintf _snprintf
+#endif
+
 #ifndef local
 #  define local static
 #endif