From 4d13e6fb8870d11dd3ca40c18a573004496016d0 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 4 Sep 2016 11:15:27 +0100 Subject: [PATCH] Do not crash whenever S matches the whole selection and hence does not select anything Fixes #787 --- src/selectors.cc | 3 +++ test/regression/787-crash-after-S/cmd | 1 + test/regression/787-crash-after-S/in | 0 test/regression/787-crash-after-S/out | 0 4 files changed, 4 insertions(+) create mode 100644 test/regression/787-crash-after-S/cmd create mode 100644 test/regression/787-crash-after-S/in create mode 100644 test/regression/787-crash-after-S/out diff --git a/src/selectors.cc b/src/selectors.cc index 24319037..d683ce98 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -691,6 +691,9 @@ void split_selections(SelectionList& selections, const Regex& regex, unsigned ca if (begin.coord() <= sel.max()) result.push_back(keep_direction({ begin.coord(), sel.max() }, sel)); } + if (result.empty()) + throw runtime_error("nothing selected"); + selections = std::move(result); } diff --git a/test/regression/787-crash-after-S/cmd b/test/regression/787-crash-after-S/cmd new file mode 100644 index 00000000..5b89052b --- /dev/null +++ b/test/regression/787-crash-after-S/cmd @@ -0,0 +1 @@ +S. diff --git a/test/regression/787-crash-after-S/in b/test/regression/787-crash-after-S/in new file mode 100644 index 00000000..e69de29b diff --git a/test/regression/787-crash-after-S/out b/test/regression/787-crash-after-S/out new file mode 100644 index 00000000..e69de29b