From 3400f670596b39c43aba5d50fdb41e1a9664c344 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Sat, 5 May 2007 05:42:34 +0000 Subject: [PATCH] Fix crashes in out-of-range clicks --- Sources/VLModel.cpp | 11 +++++++++-- Sources/VLSheetViewChords.mm | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Sources/VLModel.cpp b/Sources/VLModel.cpp index fc81369..10cad58 100644 --- a/Sources/VLModel.cpp +++ b/Sources/VLModel.cpp @@ -1499,7 +1499,7 @@ std::string VLSong::GetWord(size_t stanza, size_t measure, VLFraction at) { std::string word; - do { + while (measure < fMeasures.size()) { VLMeasure & meas = fMeasures[measure]; VLNoteList::iterator note = meas.fMelody.begin(); VLNoteList::iterator end = meas.fMelody.end(); @@ -1519,13 +1519,20 @@ std::string VLSong::GetWord(size_t stanza, size_t measure, VLFraction at) ++note; } at = 0; - } while (++measure < fMeasures.size()); + ++measure; + } return word; } void VLSong::SetWord(size_t stanza, size_t measure, VLFraction at, std::string word, size_t * nextMeas, VLFract * nextAt) { + // + // Always keep an empty measure in reserve + // + while (measure+1 >= fMeasures.size()) + AddMeasure(); + uint8_t kind = 0; bool cleanup = false; diff --git a/Sources/VLSheetViewChords.mm b/Sources/VLSheetViewChords.mm index 12f5930..e6900dc 100644 --- a/Sources/VLSheetViewChords.mm +++ b/Sources/VLSheetViewChords.mm @@ -87,6 +87,9 @@ std::string NormalizeName(NSString* rawName) - (NSString *) stringValue { + if (fMeasure >= fSong->CountMeasures()) + return @""; + const VLMeasure measure = fSong->fMeasures[fMeasure]; const VLChordList & chords = measure.fChords; VLFraction at(0);