From 53f83c31b01e798299b98aaf5ccaf61aa99b8109 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Fri, 2 Jun 2023 16:08:45 +0200 Subject: [PATCH] Codechange: use std::string to return the debug level information --- src/debug.cpp | 20 ++++++-------------- src/debug.h | 2 +- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/debug.cpp b/src/debug.cpp index 8876fdd021..46d6495324 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -220,22 +220,14 @@ void SetDebugString(const char *s, void (*error_func)(const std::string &)) * Just return a string with the values of all the debug categories. * @return string with debug-levels */ -const char *GetDebugString() +std::string GetDebugString() { - const DebugLevel *i; - static char dbgstr[150]; - char dbgval[20]; - - memset(dbgstr, 0, sizeof(dbgstr)); - i = debug_level; - seprintf(dbgstr, lastof(dbgstr), "%s=%d", i->name, *i->level); - - for (i++; i != endof(debug_level); i++) { - seprintf(dbgval, lastof(dbgval), ", %s=%d", i->name, *i->level); - strecat(dbgstr, dbgval, lastof(dbgstr)); + std::string result; + for (const DebugLevel *i = debug_level; i != endof(debug_level); ++i) { + if (!result.empty()) result += ", "; + fmt::format_to(std::back_inserter(result), "{}={}", i->name, *i->level); } - - return dbgstr; + return result; } /** diff --git a/src/debug.h b/src/debug.h index 2db1d1132b..c2f24e1494 100644 --- a/src/debug.h +++ b/src/debug.h @@ -58,7 +58,7 @@ extern int _debug_random_level; void DumpDebugFacilityNames(std::back_insert_iterator &output_iterator); void SetDebugString(const char *s, void (*error_func)(const std::string &)); -const char *GetDebugString(); +std::string GetDebugString(); /* Shorter form for passing filename and linenumber */ #define FILE_LINE __FILE__, __LINE__