Make a copy of the probe string to fix warning
The newest version of gcc uncovered a subtle bug where we were relying
on a reference to an rvalue in a loop. How this manifested was that
probeCommand was of type nlohmann::json, which has begin() and end()
overloads for std::string, but would return by value instead of by
reference to the nlohmann internals. Because of this, technically the
reference we were looking at is destroyed each iteration of the loop.
This never caused an issue in practice, as the lifetime of probeCommand
was always greater than probe, but it's good to not rely on undefined
behavior.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ie89df5d69236331de68788a7f3c5af862160c069
diff --git a/src/EntityManager.cpp b/src/EntityManager.cpp
index 7cfcc6e..84d68c6 100644
--- a/src/EntityManager.cpp
+++ b/src/EntityManager.cpp
@@ -1587,7 +1587,7 @@
// parse out dbus probes by discarding other probe types, store in a
// map
- for (const std::string& probe : probeCommand)
+ for (const std::string probe : probeCommand)
{
bool found = false;
boost::container::flat_map<const char*, probe_type_codes,