Varargs and strbuf fixes

Add missing va_end() for all va_copy()
strbuf_sprintf() adds precautionary nul to end of string after vsnprintf()
This commit is contained in:
Andrew Bettison 2012-05-22 10:23:56 +09:30
parent 3866352340
commit 29502d8c81
3 changed files with 4 additions and 0 deletions

View File

@ -376,6 +376,7 @@ int cli_printf(const char *fmt, ...)
} else } else
#endif #endif
ret = vfprintf(stdout, fmt, ap2); ret = vfprintf(stdout, fmt, ap2);
va_end(ap2);
va_end(ap); va_end(ap);
return ret; return ret;
} }

View File

@ -64,6 +64,7 @@ int form_rhizome_datastore_path(char * buf, size_t bufsiz, const char *fmt, ...)
va_list ap2; va_list ap2;
va_copy(ap2, ap); va_copy(ap2, ap);
strbuf_sprintf(b, fmt, ap2); strbuf_sprintf(b, fmt, ap2);
va_end(ap2);
va_end(ap); va_end(ap);
if (strbuf_overrun(b)) { if (strbuf_overrun(b)) {
WHY("Path buffer overrun"); WHY("Path buffer overrun");
@ -158,6 +159,7 @@ long long sqlite_exec_int64(char *sqlformat,...)
vsnprintf(sqlstatement,8192,sqlformat,ap2); sqlstatement[8191]=0; vsnprintf(sqlstatement,8192,sqlformat,ap2); sqlstatement[8191]=0;
va_end(ap2);
va_end(ap); va_end(ap);
sqlite3_stmt *statement; sqlite3_stmt *statement;

View File

@ -80,6 +80,7 @@ int strbuf_vsprintf(strbuf sb, const char *fmt, va_list ap)
int n; int n;
if (sb->start && sb->current < sb->end) { 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, ap2);
*sb->end = '\0';
} else { } else {
char tmp[1]; char tmp[1];
n = vsnprintf(tmp, sizeof tmp, fmt, ap2); n = vsnprintf(tmp, sizeof tmp, fmt, ap2);