From 59e58da2f4e78efba6d872c87d9976cad216ed86 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Wed, 23 May 2012 16:07:52 +0930 Subject: [PATCH] More fixes for varargs stuff But still no luck on Android --- commandline.c | 20 ++++++++++++-------- log.c | 5 +---- rhizome_database.c | 15 ++++----------- strbuf.c | 7 ++----- 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/commandline.c b/commandline.c index e43d405d..dec48655 100644 --- a/commandline.c +++ b/commandline.c @@ -359,25 +359,29 @@ int cli_puts(const char *str) int cli_printf(const char *fmt, ...) { int ret = 0; - va_list ap,ap2; - va_start(ap,fmt); - va_copy(ap2,ap); + va_list ap; #ifdef HAVE_JNI_H if (jni_env) { size_t avail = outv_limit - outv_current; - int count = vsnprintf(outv_current, avail, fmt, ap2); + va_start(ap, fmt); + int count = vsnprintf(outv_current, avail, fmt, ap); + va_end(ap); if (count >= avail) { if (outv_growbuf(count) == -1) return -1; - vsprintf(outv_current, fmt, ap2); + va_start(ap, fmt); + vsprintf(outv_current, fmt, ap); + va_end(ap); } outv_current += count; ret = count; } else #endif - ret = vfprintf(stdout, fmt, ap2); - va_end(ap2); - va_end(ap); + { + va_start(ap, fmt); + ret = vfprintf(stdout, fmt, ap); + va_end(ap); + } return ret; } diff --git a/log.c b/log.c index cfa96d32..dc3be60b 100644 --- a/log.c +++ b/log.c @@ -37,11 +37,8 @@ void logMessage(int level, char *fmt, ...) void vlogMessage(int level, char *fmt, va_list ap) { - va_list ap2; char buf[8192]; - va_copy(ap2, ap); - vsnprintf(buf, sizeof buf, fmt, ap2); - va_end(ap2); + vsnprintf(buf, sizeof buf, fmt, ap); buf[sizeof buf - 1] = '\0'; #ifdef ANDROID int alevel = ANDROID_LOG_UNKNOWN; diff --git a/rhizome_database.c b/rhizome_database.c index 46981a84..30990275 100644 --- a/rhizome_database.c +++ b/rhizome_database.c @@ -61,10 +61,7 @@ int form_rhizome_datastore_path(char * buf, size_t bufsiz, const char *fmt, ...) strbuf_sprintf(b, "%s/", rhizome_datastore_path()); va_list ap; va_start(ap, fmt); - va_list ap2; - va_copy(ap2, ap); - strbuf_sprintf(b, fmt, ap2); - va_end(ap2); + strbuf_sprintf(b, fmt, ap); va_end(ap); if (strbuf_overrun(b)) { WHY("Path buffer overrun"); @@ -151,15 +148,11 @@ long long sqlite_exec_int64(char *sqlformat,...) { if (!rhizome_db) rhizome_opendb(); - va_list ap,ap2; char sqlstatement[8192]; - va_start(ap,sqlformat); - va_copy(ap2,ap); - - vsnprintf(sqlstatement,8192,sqlformat,ap2); sqlstatement[8191]=0; - - va_end(ap2); + va_list ap; + va_start(ap, sqlformat); + vsnprintf(sqlstatement,8192,sqlformat,ap); sqlstatement[8191]=0; va_end(ap); sqlite3_stmt *statement; diff --git a/strbuf.c b/strbuf.c index 6cc5bc89..34c01e79 100644 --- a/strbuf.c +++ b/strbuf.c @@ -75,19 +75,16 @@ int strbuf_sprintf(strbuf sb, const char *fmt, ...) int strbuf_vsprintf(strbuf sb, const char *fmt, va_list ap) { - va_list ap2; - va_copy(ap2, ap); int n; if (sb->start && sb->current < sb->end) { - n = vsnprintf(sb->current, sb->end - sb->current + 1, fmt, ap2); + n = vsnprintf(sb->current, sb->end - sb->current + 1, fmt, ap); *sb->end = '\0'; } else { char tmp[1]; - n = vsnprintf(tmp, sizeof tmp, fmt, ap2); + n = vsnprintf(tmp, sizeof tmp, fmt, ap); } if (n != -1) sb->current += n; - va_end(ap2); return n; }