From 1a4737cd20fcb6b7056398d1a0fa583a6e1542e7 Mon Sep 17 00:00:00 2001 From: potatoalienof13 Date: Sat, 17 Dec 2022 15:29:56 -0500 Subject: [PATCH 1/4] should not succeed when run on the first character of a file. --- src/selectors.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/selectors.cc b/src/selectors.cc index 3d9b453d..febcde78 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -420,6 +420,15 @@ select_to_reverse(const Context& context, const Selection& selection, Codepoint c, int count, bool inclusive) { auto& buffer = context.buffer(); + + // if we are selecting backwards from the beginning of the buffer, + // there is nothing more that can be selected. + // Unless its inclusive, in which its possible that the current + // location of the cursor contains the Codepoint being looked for. + if(!inclusive && selection.cursor() == buffer.begin()){ + return {}; + } + Utf8Iterator begin{buffer.iterator_at(selection.cursor()), buffer}; Utf8Iterator end = begin; do From eb447f1c43cf3f057ac8335ed87f2281c914e8ca Mon Sep 17 00:00:00 2001 From: potatoalienof13 Date: Fri, 23 Dec 2022 11:52:02 -0500 Subject: [PATCH 3/4] Remove a check for inclusivity in select_to_reverse. It turns out that neither or make sense when run at the beginning of the buffer. When I first created the check, I thought that made sense if the character under the cursor was the character being searched for. I was wrong, should always go at least one character backwards. --- src/selectors.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/selectors.cc b/src/selectors.cc index febcde78..4769c19e 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -423,11 +423,8 @@ select_to_reverse(const Context& context, const Selection& selection, // if we are selecting backwards from the beginning of the buffer, // there is nothing more that can be selected. - // Unless its inclusive, in which its possible that the current - // location of the cursor contains the Codepoint being looked for. - if(!inclusive && selection.cursor() == buffer.begin()){ + if (selection.cursor() == buffer.begin()) return {}; - } Utf8Iterator begin{buffer.iterator_at(selection.cursor()), buffer}; Utf8Iterator end = begin; From 96ddc4cd4588b57a1bf316db9c1732e9b53ebdfd Mon Sep 17 00:00:00 2001 From: potatoalienof13 Date: Fri, 23 Dec 2022 11:57:30 -0500 Subject: [PATCH 4/4] Add a regression test for on an 'empty' file. --- test/regression/4471-crash-on-alt-t-with-one-char-file/cmd | 1 + test/regression/4471-crash-on-alt-t-with-one-char-file/in | 0 2 files changed, 1 insertion(+) create mode 100644 test/regression/4471-crash-on-alt-t-with-one-char-file/cmd create mode 100644 test/regression/4471-crash-on-alt-t-with-one-char-file/in diff --git a/test/regression/4471-crash-on-alt-t-with-one-char-file/cmd b/test/regression/4471-crash-on-alt-t-with-one-char-file/cmd new file mode 100644 index 00000000..ecd63ea5 --- /dev/null +++ b/test/regression/4471-crash-on-alt-t-with-one-char-file/cmd @@ -0,0 +1 @@ + diff --git a/test/regression/4471-crash-on-alt-t-with-one-char-file/in b/test/regression/4471-crash-on-alt-t-with-one-char-file/in new file mode 100644 index 00000000..e69de29b