From fc63eef69556637433b1351d0e8d2c4638883122 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 17 May 2020 13:55:54 +0200 Subject: [PATCH] Fix crash when selecting previous paragraph at buffer begin Fixes #3489 When there are multiple empty lines between a paragraph and the cursor (C in the example below), p skips over one of them. Prevent the check for the extra newline from going out of bounds. ``` a paragraph C after p, the first two lines will be selected ``` --- src/selectors.cc | 2 +- test/regression/3489-crash-on-paragraph-begin/cmd | 1 + test/regression/3489-crash-on-paragraph-begin/in | 2 ++ .../regression/3489-crash-on-paragraph-begin/kak_selection_desc | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/regression/3489-crash-on-paragraph-begin/cmd create mode 100644 test/regression/3489-crash-on-paragraph-begin/in create mode 100644 test/regression/3489-crash-on-paragraph-begin/kak_selection_desc diff --git a/src/selectors.cc b/src/selectors.cc index baa2d9ac..c7e126b3 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -560,7 +560,7 @@ select_paragraph(const Context& context, const Selection& selection, BufferIterator first = buffer.iterator_at(selection.cursor()); if (not (flags & ObjectFlags::ToEnd) and first.coord() > BufferCoord{0,1} and - is_eol(*(first-1)) and is_eol(*(first-2))) + is_eol(*(first-1)) and first-1 != buffer.begin() and is_eol(*(first-2))) --first; else if ((flags & ObjectFlags::ToEnd) and first != buffer.begin() and (first+1) != buffer.end() and diff --git a/test/regression/3489-crash-on-paragraph-begin/cmd b/test/regression/3489-crash-on-paragraph-begin/cmd new file mode 100644 index 00000000..957dd0c1 --- /dev/null +++ b/test/regression/3489-crash-on-paragraph-begin/cmd @@ -0,0 +1 @@ +jp diff --git a/test/regression/3489-crash-on-paragraph-begin/in b/test/regression/3489-crash-on-paragraph-begin/in new file mode 100644 index 00000000..139597f9 --- /dev/null +++ b/test/regression/3489-crash-on-paragraph-begin/in @@ -0,0 +1,2 @@ + + diff --git a/test/regression/3489-crash-on-paragraph-begin/kak_selection_desc b/test/regression/3489-crash-on-paragraph-begin/kak_selection_desc new file mode 100644 index 00000000..ac6a6d5b --- /dev/null +++ b/test/regression/3489-crash-on-paragraph-begin/kak_selection_desc @@ -0,0 +1 @@ +2.1,1.1