From ebbc0b09e93e6633a44c896653ad06aeccb22e91 Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Fri, 10 Jun 2022 07:49:29 +0200 Subject: [PATCH] GUI: Fix dangling pointer when _headerEntryList was reallocated As we know the size of the array in advance we can preallocate it. --- gui/widgets/grid.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gui/widgets/grid.cpp b/gui/widgets/grid.cpp index 38352ebe006..9f3462087c4 100644 --- a/gui/widgets/grid.cpp +++ b/gui/widgets/grid.cpp @@ -470,6 +470,9 @@ void GridWidget::sortGroups() { // No filter -> display everything with group headers Common::sort(_groupHeaders.begin(), _groupHeaders.end()); + // Avoid reallocation during iteration: that would invalidate our _sortedEntryList items + _headerEntryList.reserve(_groupHeaders.size()); + for (uint i = 0; i != _groupHeaders.size(); ++i) { Common::U32String header = _groupHeaders[i]; Common::U32String displayedHeader;