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.
This commit is contained in:
Mark Liversedge
2015-07-05 09:40:22 +01:00
parent 805772a2c4
commit ec893f2b7c
2 changed files with 22 additions and 0 deletions

View File

@@ -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());

View File

@@ -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);
}
}