From a45b5d042453b9ed5b0fb3d96108573e0124ba6c Mon Sep 17 00:00:00 2001
From: patrick96
Date: Fri, 11 Dec 2020 22:10:20 +0100
Subject: [PATCH] fix(build): UB when converting strings in logger
The memory returned was no longer valid because arg is destructed after
the function returns.
---
include/components/logger.hpp | 2 +-
src/components/logger.cpp | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/include/components/logger.hpp b/include/components/logger.hpp
index 5c7d1ba2..0d270927 100644
--- a/include/components/logger.hpp
+++ b/include/components/logger.hpp
@@ -100,7 +100,7 @@ class logger {
/**
* Convert string
*/
- const char* convert(string arg) const; // NOLINT
+ const char* convert(const string& arg) const;
/**
* Convert thread id
diff --git a/src/components/logger.cpp b/src/components/logger.cpp
index f482eeaf..f1e968c8 100644
--- a/src/components/logger.cpp
+++ b/src/components/logger.cpp
@@ -1,6 +1,7 @@
+#include "components/logger.hpp"
+
#include
-#include "components/logger.hpp"
#include "errors.hpp"
#include "settings.hpp"
#include "utils/concurrency.hpp"
@@ -12,7 +13,7 @@ POLYBAR_NS
/**
* Convert string
*/
-const char* logger::convert(string arg) const { // NOLINT
+const char* logger::convert(const string& arg) const {
return arg.c_str();
}