great, the ONE time i remember trunk fmt i forget to cppcheck ...

This commit is contained in:
Thomas Göttgens 2023-02-07 01:30:55 +01:00
parent b952c35da6
commit 4ac0de21ab
2 changed files with 4 additions and 2 deletions

View File

@ -5,6 +5,7 @@
#include "configuration.h" #include "configuration.h"
#include <assert.h> #include <assert.h>
#include <cstring> #include <cstring>
#include <memory>
#include <stdexcept> #include <stdexcept>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
@ -177,14 +178,14 @@ void RedirectablePrint::hexDump(const char *logLevel, unsigned char *buf, uint16
std::string RedirectablePrint::mt_sprintf(const std::string fmt_str, ...) std::string RedirectablePrint::mt_sprintf(const std::string fmt_str, ...)
{ {
int final_n, n = ((int)fmt_str.size()) * 2; /* Reserve two times as much as the length of the fmt_str */ int n = ((int)fmt_str.size()) * 2; /* Reserve two times as much as the length of the fmt_str */
std::unique_ptr<char[]> formatted; std::unique_ptr<char[]> formatted;
va_list ap; va_list ap;
while (1) { while (1) {
formatted.reset(new char[n]); /* Wrap the plain char array into the unique_ptr */ formatted.reset(new char[n]); /* Wrap the plain char array into the unique_ptr */
strcpy(&formatted[0], fmt_str.c_str()); strcpy(&formatted[0], fmt_str.c_str());
va_start(ap, fmt_str); va_start(ap, fmt_str);
final_n = vsnprintf(&formatted[0], n, fmt_str.c_str(), ap); int final_n = vsnprintf(&formatted[0], n, fmt_str.c_str(), ap);
va_end(ap); va_end(ap);
if (final_n < 0 || final_n >= n) if (final_n < 0 || final_n >= n)
n += abs(final_n - n + 1); n += abs(final_n - n + 1);

View File

@ -43,3 +43,4 @@ postfixOperator:*/mqtt/*
missingOverride missingOverride
virtualCallInConstructor virtualCallInConstructor
passedByValue:*/RedirectablePrint.h