From 5d9f05669edb407c5a78a9ff56c87b681e2145ee Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Mon, 18 Oct 2021 15:09:02 +0800 Subject: [PATCH] =?UTF-8?q?mk=5Flog=5Fprintf=E6=94=B9=E7=94=A8vasprintf?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- api/source/mk_util.cpp | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index ee7ae998..be74074d 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit ee7ae998aa5449a72ccb9615104b2198bc971a65 +Subproject commit be74074d382a43e970de05fe88f412e5a05e38d6 diff --git a/api/source/mk_util.cpp b/api/source/mk_util.cpp index 18c21fef..6f50e185 100644 --- a/api/source/mk_util.cpp +++ b/api/source/mk_util.cpp @@ -11,6 +11,7 @@ #include "mk_util.h" #include #include +#include "Util/util.h" #include "Util/logger.h" using namespace std; using namespace toolkit; @@ -47,12 +48,12 @@ API_EXPORT char* API_CALL mk_util_hex_dump(const void *buf, int len){ API_EXPORT void API_CALL mk_log_printf(int level, const char *file, const char *function, int line, const char *fmt, ...) { assert(file && function && fmt); LogContextCapturer info(Logger::Instance(), (LogLevel) level, file, function, line); - va_list pArg; - va_start(pArg, fmt); - char buf[4096]; - auto n = vsnprintf(buf, sizeof(buf), fmt, pArg); - buf[n] = '\0'; - va_end(pArg); - info << buf; + va_list ap; + va_start(ap, fmt); + char *str = nullptr; + vasprintf(&str, fmt, ap); + va_end(ap); + info << str; + free(str); }