From 0225563b46ab3efc6383069410b9c2d365b6a3b1 Mon Sep 17 00:00:00 2001 From: Hannes Schulze <43932053+hannesschulze@users.noreply.github.com> Date: Sun, 28 Jun 2020 21:07:17 +0200 Subject: [PATCH] Fix Undefined Behavior in LastAddedAreaCache (#211) --- src/DockContainerWidget.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 597299d..e0bc72c 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1319,9 +1319,9 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area) internal::hideEmptyParentSplitters(Splitter); // Remove this area from cached areas - const auto& cache = d->LastAddedAreaCache; - if (auto p = std::find(cache, cache+sizeof(cache)/sizeof(cache[0]), area)) { - d->LastAddedAreaCache[std::distance(cache, p)] = nullptr; + auto p = std::find(std::begin(d->LastAddedAreaCache), std::end(d->LastAddedAreaCache), area); + if (p != std::end(d->LastAddedAreaCache)) { + *p = nullptr; } // If splitter has more than 1 widgets, we are finished and can leave