[vlc-devel] [PATCH 4/5] win32: fix %zu fixups - dont use mingw's vsnprintf

davidf+nntp at woaf.net davidf+nntp at woaf.net
Thu Mar 26 15:22:31 CET 2009


From: David Flynn <davidf at rd.bbc.co.uk>

Traditionally, MSVCRT has provided vsnprintf as _vsnprintf;
to 'aid' portability/standards compliance, mingw provide a
static version of [v]snprintf that is buggy.

The bug manifests as %lx is treated as a 64bit argument not
32bit, ie consumes two 32bit parameters.  if a %s were to
follow a %lx, bad things can happen.

Solution: Be sure to use the MSVCRT version, at least it
behaves as expected

Additionally, make it a bit more obvious when vlc wrappers
are being called by other wrappers.

Signed-off-by: David Flynn <davidf at rd.bbc.co.uk>
---
 include/vlc_fixups.h |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 15172b2..02cf88c 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -124,7 +124,11 @@ static inline int vlc_vsprintf (char *str, const char *format, va_list ap)
 static inline int vlc_vsnprintf (char *str, size_t size, const char *format, va_list ap)
 {
     char *fmt = vlc_fix_format_string (format);
-    int ret = vsnprintf (str, size, fmt ? fmt : format, ap);
+    /* traditionally, MSVCRT has provided vsnprintf as _vsnprintf;
+     * to 'aid' portability/standards compliance, mingw provides a
+     * static version of vsnprintf that is buggy.  Be sure to use
+     * MSVCRT version, at least it behaves as expected */
+    int ret = _vsnprintf (str, size, fmt ? fmt : format, ap);
     free (fmt);
     return ret;
 }
@@ -135,7 +139,7 @@ static inline int vlc_printf (const char *format, ...)
     va_list ap;
     int ret;
     va_start (ap, format);
-    ret = vprintf (format, ap);
+    ret = vlc_vprintf (format, ap);
     va_end (ap);
     return ret;
 }
@@ -146,7 +150,7 @@ static inline int vlc_fprintf (FILE *stream, const char *format, ...)
     va_list ap;
     int ret;
     va_start (ap, format);
-    ret = vfprintf (stream, format, ap);
+    ret = vlc_vfprintf (stream, format, ap);
     va_end (ap);
     return ret;
 }
@@ -158,7 +162,7 @@ static inline int vlc_sprintf (char *str, const char *format, ...)
     va_list ap;
     int ret;
     va_start (ap, format);
-    ret = vsprintf (str, format, ap);
+    ret = vlc_vsprintf (str, format, ap);
     va_end (ap);
     return ret;
 }
@@ -170,10 +174,12 @@ static inline int vlc_snprintf (char *str, size_t size, const char *format, ...)
     va_list ap;
     int ret;
     va_start (ap, format);
-    ret = vsnprintf (str, size, format, ap);
+    ret = vlc_vsnprintf (str, size, format, ap);
     va_end (ap);
     return ret;
 }
+/* win32: snprintf must always be vlc_snprintf or _snprintf,
+ * see comment in vlc_vsnprintf */
 # define snprintf vlc_snprintf
 
 /* Make sure we don't use flawed vasprintf or asprintf either */
-- 
1.5.6.5




More information about the vlc-devel mailing list