Skip to content

Commit

Permalink
Merge pull request #1512 from skef/bg1504
Browse files Browse the repository at this point in the history
Copy va_list for second use (and add va_end's to avoid leaking)
  • Loading branch information
skef committed Jun 1, 2022
2 parents 1a80bc5 + d8ea8d8 commit 8fe509a
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 8fe509a

Please sign in to comment.