From 17ab6e851a3dc7a0c219e927255b5bd133284380 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 3 Sep 2023 23:48:42 +0200 Subject: [PATCH] - make sure that FileWriter::Printf never writes null characters. --- src/common/filesystem/source/files.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/filesystem/source/files.cpp b/src/common/filesystem/source/files.cpp index 5cb1bd343..8a0b5ed27 100644 --- a/src/common/filesystem/source/files.cpp +++ b/src/common/filesystem/source/files.cpp @@ -481,11 +481,11 @@ size_t FileWriter::Printf(const char *fmt, ...) va_start(arglist, fmt); auto n = vsnprintf(c, 300, fmt, arglist); std::string buf; - buf.resize(n); + buf.resize(n + 1); va_start(arglist, fmt); - vsnprintf(&buf.front(), n, fmt, arglist); + vsnprintf(&buf.front(), n + 1, fmt, arglist); va_end(arglist); - return Write(buf.c_str(), n); + return Write(buf.c_str(), strlen(buf.c_str())); // Make sure we write no null bytes. } size_t BufferWriter::Write(const void *buffer, size_t len)