When running cppcheck (see Travis build log), it detects the following errors:
[Building.cpp:2783]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour
[Building.cpp:2788]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour
[Building.cpp:2821]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour
[Building.cpp:2830]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour
[Building.cpp:2840]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour
[Building.cpp:2860]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour
[Building.cpp:2878]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour
[Game.cpp:1560] -> [Game.cpp:1559]: (error) Iterator 'bi' used after element has been erased.
Focusing on the last error:
[Game.cpp:1560] -> [Game.cpp:1559]: (error) Iterator 'bi' used after element has been erased.
These are the lines it is about:
for (std::list<Building *>::iterator bi=teams[ti]->virtualBuildings.begin(); bi!=teams[ti]->virtualBuildings.end(); ++bi)
if ((*bi)->posX==x && (*bi)->posY==y)
{
teams[ti]->virtualBuildings.erase(bi); //1559
teams[ti]->myBuildings[Building::GIDtoID((*bi)->gid)]=NULL; //1560
delete *bi;
found=true;
break;
}
Changing the order to this fixes the cppcheck error:
for (std::list<Building *>::iterator bi=teams[ti]->virtualBuildings.begin(); bi!=teams[ti]->virtualBuildings.end(); ++bi)
if ((*bi)->posX==x && (*bi)->posY==y)
{
teams[ti]->myBuildings[Building::GIDtoID((*bi)->gid)]=NULL;
delete *bi;
teams[ti]->virtualBuildings.erase(bi);
found=true;
break;
}
When running
cppcheck
(see Travis build log), it detects the following errors:Focusing on the last error:
These are the lines it is about:
Changing the order to this fixes the
cppcheck
error: