Skip to content

Commit

Permalink
Copy va_list for second use (and add va_end's to avoid leaking)
Browse files Browse the repository at this point in the history
  • Loading branch information
skef committed May 31, 2022
1 parent 1a80bc5 commit d8ea8d8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions c/makeotf/lib/hotconv/FeatCtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,19 @@ void FeatCtx::msgPrefix(char **premsg, char **prefix) {
}

void FeatCtx::featMsg(int msgType, const char *fmt, ...) {
va_list ap;
va_list ap, cap;
std::vector<char> buf;
buf.resize(128);

va_start(ap, fmt);
va_copy(cap, ap);
int l = vsnprintf(buf.data(), 128, fmt, ap) + 1;
va_end(ap);
if ( l > 128 ) {
buf.resize(l);
vsnprintf(buf.data(), l, fmt, ap);
vsnprintf(buf.data(), l, fmt, cap);
}
va_end(cap);
hotMsg(g, msgType, buf.data());
}

Expand Down

0 comments on commit d8ea8d8

Please sign in to comment.