Mercurial > hg > svcore
comparison data/fileio/MIDIFileReader.cpp @ 964:6b5e1edd95fc
Fix to iterator invalidation (from coverity scan)
| author | Chris Cannam |
|---|---|
| date | Wed, 03 Sep 2014 10:49:38 +0100 |
| parents | 12e62865fd61 |
| children | 2d5a8219b4b0 |
comparison
equal
deleted
inserted
replaced
| 963:12e62865fd61 | 964:6b5e1edd95fc |
|---|---|
| 659 { | 659 { |
| 660 bool notesOnTrack = false; | 660 bool notesOnTrack = false; |
| 661 bool noteOffFound; | 661 bool noteOffFound; |
| 662 | 662 |
| 663 for (MIDITrack::iterator i = m_midiComposition[track].begin(); | 663 for (MIDITrack::iterator i = m_midiComposition[track].begin(); |
| 664 i != m_midiComposition[track].end(); i++) { | 664 i != m_midiComposition[track].end(); ) { |
| 665 | |
| 666 MIDITrack::iterator nexti = i; | |
| 667 ++nexti; | |
| 665 | 668 |
| 666 if ((*i)->getMessageType() == MIDI_NOTE_ON && (*i)->getVelocity() > 0) { | 669 if ((*i)->getMessageType() == MIDI_NOTE_ON && (*i)->getVelocity() > 0) { |
| 667 | 670 |
| 668 notesOnTrack = true; | 671 notesOnTrack = true; |
| 669 noteOffFound = false; | 672 noteOffFound = false; |
| 676 ((*j)->getMessageType() == MIDI_NOTE_OFF || | 679 ((*j)->getMessageType() == MIDI_NOTE_OFF || |
| 677 ((*j)->getMessageType() == MIDI_NOTE_ON && | 680 ((*j)->getMessageType() == MIDI_NOTE_ON && |
| 678 (*j)->getVelocity() == 0x00))) { | 681 (*j)->getVelocity() == 0x00))) { |
| 679 | 682 |
| 680 (*i)->setDuration((*j)->getTime() - (*i)->getTime()); | 683 (*i)->setDuration((*j)->getTime() - (*i)->getTime()); |
| 684 | |
| 685 if (nexti == j) { | |
| 686 // we're about to erase j, invalidating nexti | |
| 687 // as well (but as this is a map, that is the | |
| 688 // only iterator to be invalidated) | |
| 689 ++nexti; | |
| 690 } | |
| 681 | 691 |
| 682 delete *j; | 692 delete *j; |
| 683 m_midiComposition[track].erase(j); | 693 m_midiComposition[track].erase(j); |
| 684 | 694 |
| 685 noteOffFound = true; | 695 noteOffFound = true; |
| 694 MIDITrack::iterator j = m_midiComposition[track].end(); | 704 MIDITrack::iterator j = m_midiComposition[track].end(); |
| 695 --j; | 705 --j; |
| 696 (*i)->setDuration((*j)->getTime() - (*i)->getTime()); | 706 (*i)->setDuration((*j)->getTime() - (*i)->getTime()); |
| 697 } | 707 } |
| 698 } | 708 } |
| 709 | |
| 710 i = nexti; | |
| 699 } | 711 } |
| 700 | 712 |
| 701 return notesOnTrack; | 713 return notesOnTrack; |
| 702 } | 714 } |
| 703 | 715 |
