From: Henrik Gramner Date: Sun, 26 Jul 2015 22:08:38 +0000 (+0200) Subject: x264_vfprintf: use va_copy X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=53b3b747e22f53204f6efb5106ab4a5a8eb57626;p=x264 x264_vfprintf: use va_copy 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. --- diff --git a/common/osdep.c b/common/osdep.c index 53478879..d3bcd417 100644 --- a/common/osdep.c +++ b/common/osdep.c @@ -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. */ diff --git a/common/osdep.h b/common/osdep.h index 2dfd00b5..f997ed1a 100644 --- a/common/osdep.h +++ b/common/osdep.h @@ -57,6 +57,10 @@ #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