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.

This commit is contained in:
Moritz Bunkus 2005-04-09 17:11:50 +00:00
parent 608b681baa
commit 78f13d2bc1
3 changed files with 17 additions and 6 deletions

View File

@ -1,3 +1,8 @@
2005-04-09 Moritz Bunkus <moritz@bunkus.org>
* all: bug fix: My output functions did not work on AMD64
systems. Fixes Anthill bug 120.
2005-04-07 Moritz Bunkus <moritz@bunkus.org>
* mkvextract: new feature: Added the extraction of the raw

View File

@ -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);

View File

@ -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__)