1
0
Fork 0

From Olaf Flebbe: avoid iterator overruns if we delete the last list entry.

This commit is contained in:
frohlich 2006-05-30 17:21:50 +00:00
parent 4f17b48e83
commit dcc77f1a7c

View file

@ -2166,7 +2166,7 @@ void FGTower::RemovePlane(const string& ID) {
// but we can only delete it once, AT THE END. // but we can only delete it once, AT THE END.
TowerPlaneRec* t = NULL; TowerPlaneRec* t = NULL;
tower_plane_rec_list_iterator twrItr; tower_plane_rec_list_iterator twrItr;
for(twrItr = appList.begin(); twrItr != appList.end(); twrItr++) { for(twrItr = appList.begin(); twrItr != appList.end();) {
if((*twrItr)->plane.callsign == ID) { if((*twrItr)->plane.callsign == ID) {
t = *twrItr; t = *twrItr;
twrItr = appList.erase(twrItr); twrItr = appList.erase(twrItr);
@ -2174,55 +2174,56 @@ void FGTower::RemovePlane(const string& ID) {
// HACK: aircraft are sometimes more than once in a list, so we need to // HACK: aircraft are sometimes more than once in a list, so we need to
// remove them all before we can delete the TowerPlaneRec class // remove them all before we can delete the TowerPlaneRec class
//break; //break;
} else
++twrItr;
} }
} for(twrItr = depList.begin(); twrItr != depList.end();) {
for(twrItr = depList.begin(); twrItr != depList.end(); twrItr++) {
if((*twrItr)->plane.callsign == ID) { if((*twrItr)->plane.callsign == ID) {
t = *twrItr; t = *twrItr;
twrItr = depList.erase(twrItr); twrItr = depList.erase(twrItr);
depListItr = depList.begin(); depListItr = depList.begin();
//break; } else
++twrItr;
} }
} for(twrItr = circuitList.begin(); twrItr != circuitList.end();) {
for(twrItr = circuitList.begin(); twrItr != circuitList.end(); twrItr++) {
if((*twrItr)->plane.callsign == ID) { if((*twrItr)->plane.callsign == ID) {
t = *twrItr; t = *twrItr;
twrItr = circuitList.erase(twrItr); twrItr = circuitList.erase(twrItr);
circuitListItr = circuitList.begin(); circuitListItr = circuitList.begin();
//break; } else
++twrItr;
} }
} for(twrItr = holdList.begin(); twrItr != holdList.end();) {
for(twrItr = holdList.begin(); twrItr != holdList.end(); twrItr++) {
if((*twrItr)->plane.callsign == ID) { if((*twrItr)->plane.callsign == ID) {
t = *twrItr; t = *twrItr;
twrItr = holdList.erase(twrItr); twrItr = holdList.erase(twrItr);
holdListItr = holdList.begin(); holdListItr = holdList.begin();
//break; } else
++twrItr;
} }
} for(twrItr = rwyList.begin(); twrItr != rwyList.end();) {
for(twrItr = rwyList.begin(); twrItr != rwyList.end(); twrItr++) {
if((*twrItr)->plane.callsign == ID) { if((*twrItr)->plane.callsign == ID) {
t = *twrItr; t = *twrItr;
twrItr = rwyList.erase(twrItr); twrItr = rwyList.erase(twrItr);
rwyListItr = rwyList.begin(); rwyListItr = rwyList.begin();
//break; } else
++twrItr;
} }
} for(twrItr = vacatedList.begin(); twrItr != vacatedList.end();) {
for(twrItr = vacatedList.begin(); twrItr != vacatedList.end(); twrItr++) {
if((*twrItr)->plane.callsign == ID) { if((*twrItr)->plane.callsign == ID) {
t = *twrItr; t = *twrItr;
twrItr = vacatedList.erase(twrItr); twrItr = vacatedList.erase(twrItr);
vacatedListItr = vacatedList.begin(); vacatedListItr = vacatedList.begin();
//break; } else
++twrItr;
} }
} for(twrItr = trafficList.begin(); twrItr != trafficList.end();) {
for(twrItr = trafficList.begin(); twrItr != trafficList.end(); twrItr++) {
if((*twrItr)->plane.callsign == ID) { if((*twrItr)->plane.callsign == ID) {
t = *twrItr; t = *twrItr;
twrItr = trafficList.erase(twrItr); twrItr = trafficList.erase(twrItr);
trafficListItr = trafficList.begin(); trafficListItr = trafficList.begin();
//break; } else
} ++twrItr;
} }
// And finally, delete the record. // And finally, delete the record.
delete t; delete t;