From 01a1e92b79e6bbebaf4b3896697ec1aebe5a9a8a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 15 Jun 2017 17:33:42 +0100 Subject: [PATCH] Fix crash recently introduced when deleting at buffer start in insert mode --- src/input_handler.cc | 6 ++++-- test/regression/0-crash-on-backspace-at-buffer-begin/cmd | 1 + test/regression/0-crash-on-backspace-at-buffer-begin/in | 1 + test/regression/0-crash-on-backspace-at-buffer-begin/out | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 test/regression/0-crash-on-backspace-at-buffer-begin/cmd create mode 100644 test/regression/0-crash-on-backspace-at-buffer-begin/in create mode 100644 test/regression/0-crash-on-backspace-at-buffer-begin/out diff --git a/src/input_handler.cc b/src/input_handler.cc index 06f1eb1e..8b91d1a4 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -1110,8 +1110,10 @@ public: sels.emplace_back(buffer.char_prev(pos)); } auto& main = context().selections().main(); - String main_char = buffer.string(buffer.char_prev(main.cursor()), - main.cursor()); + String main_char; + if (main.cursor() != BufferCoord{0, 0}) + main_char = buffer.string(buffer.char_prev(main.cursor()), + main.cursor()); if (not sels.empty()) SelectionList{buffer, std::move(sels)}.erase(); diff --git a/test/regression/0-crash-on-backspace-at-buffer-begin/cmd b/test/regression/0-crash-on-backspace-at-buffer-begin/cmd new file mode 100644 index 00000000..4329828f --- /dev/null +++ b/test/regression/0-crash-on-backspace-at-buffer-begin/cmd @@ -0,0 +1 @@ +i diff --git a/test/regression/0-crash-on-backspace-at-buffer-begin/in b/test/regression/0-crash-on-backspace-at-buffer-begin/in new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/regression/0-crash-on-backspace-at-buffer-begin/in @@ -0,0 +1 @@ + diff --git a/test/regression/0-crash-on-backspace-at-buffer-begin/out b/test/regression/0-crash-on-backspace-at-buffer-begin/out new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/regression/0-crash-on-backspace-at-buffer-begin/out @@ -0,0 +1 @@ +