From 9b031be8d15c87a6a39450d871b06c3f3bb7d01a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Apr 2020 18:57:59 +0200 Subject: [PATCH] Fix fatal bug in wxGridSelection::DeselectBlock() The selBlock reference could be used after the vector invalidation, which resulted in using the wrong vector element at best and could probably lead to a crash at worst. Don't use it after invalidating the vector any longer. This notably fixes a bug in row-or-column selection mode where the grid wasn't updated visually after modifying its selection by deselecting a single cell as soon as there were more than one selected row or column. --- src/generic/gridsel.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index bd1652f25d..2d473c0ede 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -290,14 +290,15 @@ wxGridSelection::DeselectBlock(const wxGridBlockCoords& block, break; } - // remove the block + const wxGridBlockDiffResult result = + selBlock.Difference(canonicalizedBlock, splitOrientation); + + // remove the block (note that selBlock, being a reference, is + // invalidated here and can't be used any more below) m_selection.erase(m_selection.begin() + n); n--; count--; - wxGridBlockDiffResult result = - selBlock.Difference(canonicalizedBlock, splitOrientation); - for ( int i = 0; i < 2; ++i ) { const wxGridBlockCoords& part = result.m_parts[i];