Skip to content

Commit f44dd06

Browse files
xdustinfaceUdjinM6
andauthored
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 <UdjinM6@users.noreply.github.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
1 parent fc6fe50 commit f44dd06

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/util.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,9 @@ void RenameThreadPool(ctpl::thread_pool& tp, const char* baseName);
434434
/**
435435
* .. and a wrapper that just calls func once
436436
*/
437-
template <typename Callable> void TraceThread(const char* name, Callable func)
437+
template <typename Callable> void TraceThread(const std::string name, Callable func)
438438
{
439-
std::string s = strprintf("dash-%s", name);
439+
std::string s = "dash-" + name;
440440
RenameThread(s.c_str());
441441
try
442442
{
@@ -450,7 +450,7 @@ template <typename Callable> void TraceThread(const char* name, Callable func)
450450
throw;
451451
}
452452
catch (...) {
453-
PrintExceptionContinue(std::current_exception(), name);
453+
PrintExceptionContinue(std::current_exception(), name.c_str());
454454
throw;
455455
}
456456
}

0 commit comments

Comments
 (0)