kernelshark: Prevent potential detach of QMap container
Use const_iterator instead. Fix range-loop-detach Clazy warning.
Indeed when using C++11 range-loops, the .begin() and .end() functions are
called, instead of .cbegin() and .cend(). This imply before looping over the
QMap, it may perform a deep-copy of it (if shared).
See also the explanation given by Qt documentation of qAsConst().
Another solution is to use "std::as_const" cast on the QMap object.
Signed-off-by: Benjamin ROBIN <dev@benjarobin.fr>
Signed-off-by: Yordan Karadzhov <y.karadz@gmail.com>
diff --git a/src/KsGLWidget.cpp b/src/KsGLWidget.cpp
index eda705e..9311d98 100644
--- a/src/KsGLWidget.cpp
+++ b/src/KsGLWidget.cpp
@@ -137,9 +137,10 @@
/* Draw the time axis. */
_drawAxisX(size);
- for (auto const &stream: _graphs)
- for (auto const &g: stream)
+ for (auto it = _graphs.cbegin(), end = _graphs.cend(); it != end; ++it) {
+ for (auto const &g: it.value())
g->draw(size);
+ }
for (auto const &s: _shapes) {
if (!s)
diff --git a/src/plugins/KVMComboDialog.cpp b/src/plugins/KVMComboDialog.cpp
index 0d24425..99113ed 100644
--- a/src/plugins/KVMComboDialog.cpp
+++ b/src/plugins/KVMComboDialog.cpp
@@ -308,13 +308,15 @@
int nPlots(0);
_plotMap[guestId] = _streamCombos(guestId);
- for (auto const &stream: _plotMap)
- for (auto const &combo: stream) {
+
+ for (auto it = _plotMap.cbegin(), end = _plotMap.cend(); it != end; ++it) {
+ for (auto const &combo: it.value()) {
allCombosVec.append(2);
combo[0] >> allCombosVec;
combo[1] >> allCombosVec;
++nPlots;
}
+ }
emit apply(nPlots, allCombosVec);
}