diff options
author | Benjamin ROBIN <dev@benjarobin.fr> | 2024-01-28 20:38:04 +0100 |
---|---|---|
committer | Yordan Karadzhov <y.karadz@gmail.com> | 2024-02-04 19:59:19 +0200 |
commit | 950fceeb9eebf06df8fc0af7493d230960a90dab (patch) | |
tree | 45b5319ff8bbb841f00734b8cefe8fee26653c5a | |
parent | 4f3bc9bb1fc0ebd295882d9d1331fb6de7867c0f (diff) | |
download | kernel-shark-950fceeb9eebf06df8fc0af7493d230960a90dab.tar.gz |
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>
-rw-r--r-- | src/KsGLWidget.cpp | 5 | ||||
-rw-r--r-- | src/plugins/KVMComboDialog.cpp | 6 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/KsGLWidget.cpp b/src/KsGLWidget.cpp index eda705e1..9311d98d 100644 --- a/src/KsGLWidget.cpp +++ b/src/KsGLWidget.cpp @@ -137,9 +137,10 @@ void KsGLWidget::paintGL() /* 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 0d24425c..99113ed6 100644 --- a/src/plugins/KVMComboDialog.cpp +++ b/src/plugins/KVMComboDialog.cpp @@ -308,13 +308,15 @@ void KsComboPlotDialog::_applyPress() 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); } |