From 9f45cc046921e752d813361e285b148fa91c739f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 19 Aug 2023 13:54:04 +0200 Subject: [PATCH] - use snprintf for FileWriter::Printf. pulling in stb_sprintf here may be tricky if the consuming application uses different options, so better not use it here. --- src/common/filesystem/files.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/common/filesystem/files.cpp b/src/common/filesystem/files.cpp index 10ddd3832..cd81580e6 100644 --- a/src/common/filesystem/files.cpp +++ b/src/common/filesystem/files.cpp @@ -35,7 +35,8 @@ #include #include "files.h" -#include "stb_sprintf.h" + +using namespace fs_private; using namespace fs_private; @@ -477,18 +478,16 @@ long FileWriter::Seek(long offset, int mode) size_t FileWriter::Printf(const char *fmt, ...) { - char workbuf[STB_SPRINTF_MIN]; + char c[300]; va_list arglist; va_start(arglist, fmt); - auto r = stbsp_vsprintfcb([](const char* cstr, void* data, int len) -> char* - { - auto fr = (FileWriter*)data; - auto writ = fr->Write(cstr, len); - return writ == (size_t)len? (char*)cstr : nullptr; // abort if writing caused an error. - }, this, workbuf, fmt, arglist); - + auto n = vsnprintf(c, 300, fmt, arglist); + std::string buf; + buf.resize(n); + va_start(arglist, fmt); + vsnprintf(&buf.front(), n, fmt, arglist); va_end(arglist); - return r; + return Write(buf.c_str(), n); } size_t BufferWriter::Write(const void *buffer, size_t len)