From d8ea8d89725e0bec3b03672651c08200a316801c Mon Sep 17 00:00:00 2001 From: Skef Iterum Date: Tue, 31 May 2022 16:50:23 -0700 Subject: [PATCH] Copy va_list for second use (and add va_end's to avoid leaking) --- c/makeotf/lib/hotconv/FeatCtx.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/c/makeotf/lib/hotconv/FeatCtx.cpp b/c/makeotf/lib/hotconv/FeatCtx.cpp index d87ecaa05..de31a5138 100644 --- a/c/makeotf/lib/hotconv/FeatCtx.cpp +++ b/c/makeotf/lib/hotconv/FeatCtx.cpp @@ -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 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()); }