From e505129d5cdac25c4cc07a5175f948a7887d2323 Mon Sep 17 00:00:00 2001 From: Thomas Lauf Date: Thu, 9 Feb 2017 09:18:55 +0100 Subject: [PATCH] TI-64: Command 'stop' with date before current interval's start date causes segfault - Show error message if stop date is before current interval's start date - Add test for this use case --- src/commands/CmdStop.cpp | 5 +++++ test/stop.t | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/commands/CmdStop.cpp b/src/commands/CmdStop.cpp index 3fc018ea..2c21b259 100644 --- a/src/commands/CmdStop.cpp +++ b/src/commands/CmdStop.cpp @@ -62,7 +62,12 @@ int CmdStop ( // If a stop date is specified (and occupies filter.range.start) then use // that instead of the current time. if (filter.range.start.toEpoch () != 0) + { + if (modified.range.start >= filter.range.start) + throw std::string ("The end of a date range must be after the start."); + modified.range.end = filter.range.start; + } else modified.range.end = Datetime (); diff --git a/test/stop.t b/test/stop.t index 340e35c8..8ecc233f 100755 --- a/test/stop.t +++ b/test/stop.t @@ -65,6 +65,12 @@ class TestStop(TestCase): self.assertIn('0100Z', j[0]['start']) self.assertIn('0200Z', j[0]['end']) + def test_invalid_stop(self): + """Verify stop date after start date is an error""" + self.t("start 20160516T100200") + code, out, err = self.t.runError("stop 20160516T090100") + self.assertIn("The end of a date range must be after the start.", err) + def test_stop_all(self): """Start three tags, stop""" self.t("start 5mins ago one two three")