From 81183ae7d1fbe9534db25f7565308d2833241da1 Mon Sep 17 00:00:00 2001 From: javabird25 Date: Thu, 29 Oct 2020 17:34:17 +0500 Subject: [PATCH] Fix SIGSEGV when substituting sequence with shorter one --- src/Task.cpp | 2 +- test/substitute.t | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Task.cpp b/src/Task.cpp index 9453d181e..c64f28cce 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -1393,7 +1393,7 @@ void Task::substitute ( int skew = 0; for (unsigned int i = 0; i < start.size () && !done; ++i) { - description.replace (start[i + skew], end[i] - start[i], to); + description.replace (start[i] + skew, end[i] - start[i], to); skew += to.length () - (end[i] - start[i]); ++changes; diff --git a/test/substitute.t b/test/substitute.t index 160a8feff..9ed05fb44 100755 --- a/test/substitute.t +++ b/test/substitute.t @@ -84,6 +84,14 @@ class TestSubstitutions(TestCase): code, out, err = self.t("_get 1.description") self.assertEqual("aaa BbB\n", out) + def test_substitution_long_with_short(self): + """Verify substitution of a sequence with a shorter sequence.""" + self.t("add aaaaBaaaa") + self.t("1 modify /aaaa/c/g") + code, out, err = self.t("_get 1.description") + self.assertEqual("cBc\n", out) + + class TestBug441(TestCase): def setUp(self): self.t = Task()