From 55a3f38405c6c5e5510a01a28ca0b30648a43b37 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 9 Apr 2019 22:11:11 -0700 Subject: Don't use a fixed size buffer for printed messages --- Alc/helpers.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'Alc/helpers.cpp') diff --git a/Alc/helpers.cpp b/Alc/helpers.cpp index 29b613cc..d9133842 100644 --- a/Alc/helpers.cpp +++ b/Alc/helpers.cpp @@ -358,13 +358,22 @@ void *GetSymbol(void *handle, const char *name) void al_print(const char *type, const char *prefix, const char *func, const char *fmt, ...) { - char str[1024]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(str, sizeof(str), fmt, ap); - va_end(ap); - str[sizeof(str)-1] = 0; + al::vector dynmsg; + char stcmsg[256]; + char *str{stcmsg}; + + va_list args, args2; + va_start(args, fmt); + va_copy(args2, args); + int msglen{std::vsnprintf(str, sizeof(stcmsg), fmt, args)}; + if(UNLIKELY(msglen >= 0 && static_cast(msglen) >= sizeof(stcmsg))) + { + dynmsg.resize(static_cast(msglen) + 1u); + str = dynmsg.data(); + msglen = std::vsnprintf(str, dynmsg.size(), fmt, args2); + } + va_end(args2); + va_end(args); std::wstring wstr{utf8_to_wstr(str)}; fprintf(gLogFile, "AL lib: %s %s%s: %ls", type, prefix, func, wstr.c_str()); -- cgit v1.2.3