From 78f13d2bc166e9fb9741850ba4d85601a4c56765 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sat, 9 Apr 2005 17:11:50 +0000 Subject: [PATCH] A va_list is undefined after a call to a consumer function like vsprintf. Therefore it has to be copied if it will be used multiple times. This was working on most 32bit systems but not on AMD64 anymore. Fixes Anthill bug 120. --- ChangeLog | 5 +++++ src/common/common.cpp | 16 +++++++++++----- src/common/common.h | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7c9db7120..c17e906e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-04-09 Moritz Bunkus + + * all: bug fix: My output functions did not work on AMD64 + systems. Fixes Anthill bug 120. + 2005-04-07 Moritz Bunkus * mkvextract: new feature: Added the extraction of the raw diff --git a/src/common/common.cpp b/src/common/common.cpp index 1e68c3447..ed525b1f3 100644 --- a/src/common/common.cpp +++ b/src/common/common.cpp @@ -1266,7 +1266,7 @@ mxprints(char *dst, static void mxmsg(int level, const char *fmt, - va_list &ap) { + va_list ap) { string new_fmt, output; bool nl; FILE *stream; @@ -1397,7 +1397,11 @@ get_varg_len(const char *fmt, size = 1024; dst = (char *)safemalloc(size); while (1) { - result = vsnprintf(dst, size - 1, fmt, ap); + va_list ap2; + + va_copy(ap2, ap); + result = vsnprintf(dst, size - 1, fmt, ap2); + va_end(ap2); if (result >= 0) { safefree(dst); return result; @@ -1412,16 +1416,18 @@ get_varg_len(const char *fmt, string mxvsprintf(const char *fmt, - va_list &ap) { + va_list ap) { string new_fmt, dst; char *new_string; int len; + va_list ap2; fix_format(fmt, new_fmt); len = get_varg_len(new_fmt.c_str(), ap); new_string = (char *)safemalloc(len + 1); - vsprintf(new_string, new_fmt.c_str(), ap); - va_end(ap); + va_copy(ap2, ap); + vsprintf(new_string, new_fmt.c_str(), ap2); + va_end(ap2); dst = new_string; safefree(new_string); diff --git a/src/common/common.h b/src/common/common.h index b79699522..7803e2ef4 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -131,7 +131,7 @@ void MTX_DLL_API mxverb(int level, const char *fmt, ...); void MTX_DLL_API mxdebug(const char *fmt, ...); int MTX_DLL_API mxsscanf(const string &str, const char *fmt, ...); #endif -string MTX_DLL_API mxvsprintf(const char *fmt, va_list &ap); +string MTX_DLL_API mxvsprintf(const char *fmt, va_list ap); void MTX_DLL_API mxexit(int code = -1); #define trace() _trace(__func__, __FILE__, __LINE__)