fix(build): UB when converting strings in logger

The memory returned was no longer valid because arg is destructed after
the function returns.
This commit is contained in:
patrick96 2020-12-11 22:10:20 +01:00 committed by Patrick Ziegler
parent d665634484
commit a45b5d0424
2 changed files with 4 additions and 3 deletions

View File

@ -100,7 +100,7 @@ class logger {
/** /**
* Convert string * Convert string
*/ */
const char* convert(string arg) const; // NOLINT const char* convert(const string& arg) const;
/** /**
* Convert thread id * Convert thread id

View File

@ -1,6 +1,7 @@
#include "components/logger.hpp"
#include <unistd.h> #include <unistd.h>
#include "components/logger.hpp"
#include "errors.hpp" #include "errors.hpp"
#include "settings.hpp" #include "settings.hpp"
#include "utils/concurrency.hpp" #include "utils/concurrency.hpp"
@ -12,7 +13,7 @@ POLYBAR_NS
/** /**
* Convert string * Convert string
*/ */
const char* logger::convert(string arg) const { // NOLINT const char* logger::convert(const string& arg) const {
return arg.c_str(); return arg.c_str();
} }