From ec893f2b7c6cff005bae47615cb96bb1895e7dc1 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sun, 5 Jul 2015 09:40:22 +0100 Subject: [PATCH] Check Season Range after edit/load .. to make sure the date range is not negative, since that causes SEGV all over the codebase, which assumes a date range is always positive. --- src/LTMSidebar.cpp | 14 ++++++++++++++ src/SeasonParser.cpp | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/LTMSidebar.cpp b/src/LTMSidebar.cpp index ef61b8ebb..7821f9e46 100644 --- a/src/LTMSidebar.cpp +++ b/src/LTMSidebar.cpp @@ -983,6 +983,13 @@ LTMSidebar::addRange() active = true; + // check dates are right way round... + if (newOne.start > newOne.end) { + QDate temp = newOne.start; + newOne.start = newOne.end; + newOne.end = temp; + } + // save seasons->seasons.insert(0, newOne); seasons->writeSeasons(); @@ -1011,6 +1018,13 @@ LTMSidebar::editRange() active = true; + // check dates are right way round... + if (seasons->seasons[index].start > seasons->seasons[index].end) { + QDate temp = seasons->seasons[index].start; + seasons->seasons[index].start = seasons->seasons[index].end; + seasons->seasons[index].end = temp; + } + // update name dateRangeTree->selectedItems().first()->setText(0, seasons->seasons[index].getName()); diff --git a/src/SeasonParser.cpp b/src/SeasonParser.cpp index 08d079117..39534f660 100644 --- a/src/SeasonParser.cpp +++ b/src/SeasonParser.cpp @@ -65,6 +65,14 @@ bool SeasonParser::endElement( const QString&, const QString&, const QString &qN seasons[seasons.size()-1].setEnd(season.getStart()); } if (season.getStart().isValid() && season.getEnd().isValid()) { + + // just check the dates are the right way around + if (season.start > season.end) { + QDate temp = season.start; + season.start = season.end; + season.end = temp; + } + seasons.append(season); } }