From f425316eed20d5d34e82ce33cc3d3ca5945b534e Mon Sep 17 00:00:00 2001 From: dustinface <35775977+xdustinface@users.noreply.github.com> Date: Tue, 14 Jul 2020 23:15:05 +0200 Subject: [PATCH] util: Change TraceThread's "name" type: "const char*" -> "const std::string" (#3609) Having "const char*" leads to undefined behaviour if the "const char*" is deallocated before the thread used it. Co-Authored-By: UdjinM6 Co-authored-by: UdjinM6 --- src/util.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util.h b/src/util.h index 460caa7205..50f0027098 100644 --- a/src/util.h +++ b/src/util.h @@ -433,9 +433,9 @@ void RenameThreadPool(ctpl::thread_pool& tp, const char* baseName); /** * .. and a wrapper that just calls func once */ -template void TraceThread(const char* name, Callable func) +template void TraceThread(const std::string name, Callable func) { - std::string s = strprintf("dash-%s", name); + std::string s = "dash-" + name; RenameThread(s.c_str()); try { @@ -449,7 +449,7 @@ template void TraceThread(const char* name, Callable func) throw; } catch (...) { - PrintExceptionContinue(std::current_exception(), name); + PrintExceptionContinue(std::current_exception(), name.c_str()); throw; } }