]> git.sesse.net Git - x264/commitdiff
x264_vfprintf: use va_copy
authorHenrik Gramner <henrik@gramner.com>
Sun, 26 Jul 2015 22:08:38 +0000 (00:08 +0200)
committerAnton Mitrofanov <BugMaster@narod.ru>
Tue, 18 Aug 2015 21:55:29 +0000 (00:55 +0300)
It's undefined behavior to use the same va_list twice.

This most likely didn't cause any issues in practice since the string would
have to be larger than 4 KiB to trigger the fallback path.

Use workaround for ICL as it doesn't define va_copy even for C99.

common/osdep.c
common/osdep.h

index 5347887920726ebba65ad441a6f545dd49e774a7..d3bcd417110232971e1c6d2696a49d5405b079ce 100644 (file)
@@ -141,8 +141,12 @@ int x264_vfprintf( FILE *stream, const char *format, va_list arg )
     {
         char buf[4096];
         wchar_t buf_utf16[4096];
+        va_list arg2;
+
+        va_copy( arg2, arg );
+        int length = vsnprintf( buf, sizeof(buf), format, arg2 );
+        va_end( arg2 );
 
-        int length = vsnprintf( buf, sizeof(buf), format, arg );
         if( length > 0 && length < sizeof(buf) )
         {
             /* WriteConsoleW is the most reliable way to output Unicode to a console. */
index 2dfd00b5cc567bda307fd5016d9c45ee21cbe786..f997ed1a2ee5c73547f18fe84e07dc102082c0e5 100644 (file)
 #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
 #endif
 
+#if !defined(va_copy) && defined(__INTEL_COMPILER)
+#define va_copy(dst, src) ((dst) = (src))
+#endif
+
 #if !defined(isfinite) && (SYS_OPENBSD || SYS_SunOS)
 #define isfinite finite
 #endif