[x264-devel] x264_vfprintf: use va_copy
Henrik Gramner
git at videolan.org
Wed Aug 19 21:16:12 CEST 2015
x264 | branch: master | Henrik Gramner <henrik at gramner.com> | Mon Jul 27 00:08:38 2015 +0200| [53b3b747e22f53204f6efb5106ab4a5a8eb57626] | committer: Anton Mitrofanov
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.
> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=53b3b747e22f53204f6efb5106ab4a5a8eb57626
---
common/osdep.c | 6 +++++-
common/osdep.h | 4 ++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/common/osdep.c b/common/osdep.c
index 5347887..d3bcd41 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 2dfd00b..f997ed1 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
More information about the x264-devel
mailing list