- bugfixes and code cleanup found using cppcheck
This commit is contained in:
parent
7a099a51c3
commit
9286130138
|
@ -212,6 +212,9 @@ private:
|
|||
MainWindow *mainWindow;
|
||||
|
||||
public:
|
||||
App() : wxApp() {
|
||||
mainWindow = NULL;
|
||||
}
|
||||
virtual bool OnInit();
|
||||
virtual int MainLoop();
|
||||
virtual int OnExit();
|
||||
|
|
|
@ -58,6 +58,9 @@ private:
|
|||
const Texture *teamTexture;
|
||||
|
||||
public:
|
||||
MeshCallbackTeamColor() : MeshCallback() {
|
||||
teamTexture = NULL;
|
||||
}
|
||||
void setTeamTexture(const Texture *teamTexture) {this->teamTexture= teamTexture;}
|
||||
virtual void execute(const Mesh *mesh);
|
||||
};
|
||||
|
|
|
@ -169,6 +169,7 @@ public:
|
|||
aiInterface = NULL;
|
||||
startLoc = -1;
|
||||
randomMinWarriorsReached = false;
|
||||
minWarriors = 0;
|
||||
}
|
||||
~Ai();
|
||||
|
||||
|
|
|
@ -930,7 +930,7 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){
|
|||
idle_producers.push_back(currentProducerIndex);
|
||||
}
|
||||
}
|
||||
if(idle_producers.size() > 0) {
|
||||
if(idle_producers.empty() == false) {
|
||||
producers = idle_producers;
|
||||
}
|
||||
|
||||
|
|
|
@ -1596,7 +1596,7 @@ void PathFinder::saveGame(XmlNode *rootNode) {
|
|||
nodePoolNode->addAttribute("next",intToStr(nextIdx), mapTagReplacements);
|
||||
// Node *prev;
|
||||
int prevIdx = findNodeIndex(curNode->prev, factionState.nodePool);
|
||||
nodePoolNode->addAttribute("prev",intToStr(nextIdx), mapTagReplacements);
|
||||
nodePoolNode->addAttribute("prev",intToStr(prevIdx), mapTagReplacements);
|
||||
// float heuristic;
|
||||
nodePoolNode->addAttribute("heuristic",floatToStr(curNode->heuristic), mapTagReplacements);
|
||||
// bool exploredCell;
|
||||
|
|
|
@ -336,7 +336,7 @@ const int GraphicListBox::defH= 22;
|
|||
const int GraphicListBox::defW= 140;
|
||||
|
||||
GraphicListBox::GraphicListBox(std::string containerName, std::string objName)
|
||||
: GraphicComponent(containerName, objName) {
|
||||
: GraphicComponent(containerName, objName), graphButton1(), graphButton2() {
|
||||
selectedItemIndex = 0;
|
||||
lighted = false;
|
||||
}
|
||||
|
|
|
@ -1236,7 +1236,6 @@ void Game::update() {
|
|||
// Simply show a progress message while replaying commands
|
||||
if(lastReplaySecond < chronoReplay.getSeconds()) {
|
||||
lastReplaySecond = chronoReplay.getSeconds();
|
||||
const Metrics &metrics= Metrics::getInstance();
|
||||
Renderer &renderer= Renderer::getInstance();
|
||||
renderer.clearBuffers();
|
||||
renderer.clearZBuffer();
|
||||
|
|
|
@ -966,7 +966,10 @@ void Renderer::loadCameraMatrix(const Camera *camera) {
|
|||
glTranslatef(-position.x, -position.y, -position.z);
|
||||
}
|
||||
|
||||
enum PROJECTION_TO_INFINITY { D_IS_ZERO, N_OVER_D_IS_OUTSIDE };
|
||||
enum PROJECTION_TO_INFINITY {
|
||||
D_IS_ZERO,
|
||||
N_OVER_D_IS_OUTSIDE
|
||||
};
|
||||
|
||||
static Vec2i _unprojectMap(const Vec2i& pt,const GLdouble* model,const GLdouble* projection,const GLint* viewport,const char* label=NULL) {
|
||||
Vec3d a,b;
|
||||
|
@ -6089,11 +6092,11 @@ void Renderer::selectUsingColorPicking(Selection::UnitContainer &units,
|
|||
//printf("In [%s::%s] Line: %d pickedList = %d models rendered = %d\n",__FILE__,__FUNCTION__,__LINE__,pickedList.size(),rendererModels.size());
|
||||
|
||||
if(pickedList.empty() == false) {
|
||||
for(int i = 0; i < pickedList.size(); ++i) {
|
||||
for(unsigned int i = 0; i < pickedList.size(); ++i) {
|
||||
int index = pickedList[i];
|
||||
//printf("In [%s::%s] Line: %d searching for selected object i = %d index = %d units = %d objects = %d\n",__FILE__,__FUNCTION__,__LINE__,i,index,rendererUnits.size(),rendererObjects.size());
|
||||
|
||||
if(rendererObjects.size() > 0 && index < rendererObjects.size()) {
|
||||
if(rendererObjects.empty() == false && index < rendererObjects.size()) {
|
||||
Object *object = rendererObjects[index];
|
||||
//printf("In [%s::%s] Line: %d searching for selected object i = %d index = %d [%p]\n",__FILE__,__FUNCTION__,__LINE__,i,index,object);
|
||||
|
||||
|
|
|
@ -2232,7 +2232,7 @@ void CheckForDuplicateData() {
|
|||
if(maps.empty() == true) {
|
||||
throw runtime_error("No maps were found!");
|
||||
}
|
||||
else if(invalidMapList.size() > 0) {
|
||||
else if(invalidMapList.empty() == false) {
|
||||
string errorMsg = "Warning invalid maps were detected (will be ignored):\n";
|
||||
for(int i = 0; i < invalidMapList.size(); ++i) {
|
||||
char szBuf[4096]="";
|
||||
|
|
|
@ -73,7 +73,7 @@ void ProgramState::tick() {
|
|||
bool ProgramState::canRender(bool sleepIfCannotRender) {
|
||||
int maxFPSCap = Config::getInstance().getInt("RenderFPSCap","500");
|
||||
int sleepMillis = Config::getInstance().getInt("RenderFPSCapSleepMillis","1");
|
||||
Renderer &renderer= Renderer::getInstance();
|
||||
//Renderer &renderer= Renderer::getInstance();
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
maxFPSCap = Config::getInstance().getInt("RenderFPSCapHeadless","250");
|
||||
sleepMillis = Config::getInstance().getInt("RenderFPSCapHeadlessSleepMillis","1");
|
||||
|
@ -352,7 +352,7 @@ void Program::loop() {
|
|||
void Program::loopWorker() {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] ================================= MAIN LOOP START ================================= \n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
Renderer &renderer= Renderer::getInstance();
|
||||
//Renderer &renderer= Renderer::getInstance();
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false && window) {
|
||||
MainWindow *mainWindow = dynamic_cast<MainWindow *>(window);
|
||||
if(mainWindow) {
|
||||
|
|
|
@ -187,7 +187,7 @@ public:
|
|||
void setState(ProgramState *programStateNew,bool cleanupOldState=true);
|
||||
ProgramState * getState() { return programState;}
|
||||
WindowGl * getWindow() { return window; }
|
||||
const WindowGl * getWindowConstPtr() { return window; }
|
||||
const WindowGl * getWindowConstPtr() const { return window; }
|
||||
void init(WindowGl *window, bool initSound=true, bool toggleFullScreen=false);
|
||||
void exit();
|
||||
|
||||
|
|
|
@ -439,7 +439,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||
// }
|
||||
// //listBoxMap.setItems(formattedPlayerSortedMaps[0]);
|
||||
// listBoxMap.setItems(formattedMapFiles);
|
||||
int initialMapSelection = setupMapList("");
|
||||
setupMapList("");
|
||||
listBoxMap.setItems(formattedPlayerSortedMaps[0]);
|
||||
//listBoxMap.setSelectedItemIndex(initialMapSelection);
|
||||
|
||||
|
@ -4126,7 +4126,6 @@ int MenuStateConnectedGame::setupTechList(string scenario) {
|
|||
}
|
||||
|
||||
void MenuStateConnectedGame::setupTilesetList(string scenario) {
|
||||
int initialTechSelection = 0;
|
||||
try {
|
||||
Config &config = Config::getInstance();
|
||||
|
||||
|
|
|
@ -3919,11 +3919,9 @@ void MenuStateCustomGame::processScenario() {
|
|||
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||
ConnectionSlot *slot = serverInterface->getSlot(i);
|
||||
|
||||
bool checkControTypeClicked = false;
|
||||
int selectedControlItemIndex = listBoxControls[i].getSelectedItemIndex();
|
||||
if(selectedControlItemIndex != ctNetwork ||
|
||||
(selectedControlItemIndex == ctNetwork && (slot == NULL || slot->isConnected() == false))) {
|
||||
checkControTypeClicked = true;
|
||||
}
|
||||
|
||||
listBoxControls[i].setSelectedItemIndex(scenarioInfo.factionControls[i]);
|
||||
|
@ -4297,7 +4295,6 @@ void MenuStateCustomGame::reloadFactions(bool keepExistingSelectedItem, string s
|
|||
}
|
||||
|
||||
void MenuStateCustomGame::setupTilesetList(string scenario) {
|
||||
int initialTechSelection = 0;
|
||||
try {
|
||||
Config &config = Config::getInstance();
|
||||
|
||||
|
|
|
@ -198,7 +198,6 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||
else if(deleteButton.mouseClick(x, y)) {
|
||||
soundRenderer.playFx(coreData.getClickSoundB());
|
||||
if(selectedButton == NULL) {
|
||||
Lang &lang= Lang::getInstance();
|
||||
console.addStdMessage("NothingSelected",true);
|
||||
}
|
||||
else {
|
||||
|
@ -236,7 +235,6 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||
soundRenderer.playFx(coreData.getClickSoundB());
|
||||
|
||||
if(selectedButton == NULL) {
|
||||
Lang &lang= Lang::getInstance();
|
||||
console.addStdMessage("NothingSelected",true);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -817,7 +817,7 @@ void ClientInterface::updateKeyframe(int frameCount) {
|
|||
networkCommandListThread->start();
|
||||
}
|
||||
|
||||
bool hasData = getNetworkCommand(frameCount,cachedPendingCommandsIndex);
|
||||
getNetworkCommand(frameCount,cachedPendingCommandsIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1150,7 +1150,7 @@ bool Unit::checkModelStateInfoForNewHpValue() {
|
|||
|
||||
lastModelIndexForCurrSkillType = -1;
|
||||
animationRandomCycleCount = 0;
|
||||
bool result = true;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -3625,7 +3625,7 @@ void Unit::saveGame(XmlNode *rootNode) {
|
|||
//}
|
||||
|
||||
// vector<UnitParticleSystem*> unitParticleSystems;
|
||||
if(unitParticleSystems.size() > 0) {
|
||||
if(unitParticleSystems.empty() == false) {
|
||||
XmlNode *unitParticleSystemsNode = unitNode->addChild("unitParticleSystems");
|
||||
|
||||
for(unsigned int i = 0; i < unitParticleSystems.size(); ++i) {
|
||||
|
@ -3636,7 +3636,7 @@ void Unit::saveGame(XmlNode *rootNode) {
|
|||
}
|
||||
}
|
||||
// vector<UnitParticleSystemType*> queuedUnitParticleSystemTypes;
|
||||
if(queuedUnitParticleSystemTypes.size() > 0) {
|
||||
if(queuedUnitParticleSystemTypes.empty() == false) {
|
||||
XmlNode *queuedUnitParticleSystemTypesNode = unitNode->addChild("queuedUnitParticleSystemTypes");
|
||||
for(unsigned int i = 0; i < queuedUnitParticleSystemTypes.size(); ++i) {
|
||||
UnitParticleSystemType *upst= queuedUnitParticleSystemTypes[i];
|
||||
|
@ -3646,7 +3646,7 @@ void Unit::saveGame(XmlNode *rootNode) {
|
|||
}
|
||||
}
|
||||
// UnitParticleSystems damageParticleSystems;
|
||||
if(damageParticleSystems.size() > 0) {
|
||||
if(damageParticleSystems.empty() == false) {
|
||||
XmlNode *damageParticleSystemsNode = unitNode->addChild("damageParticleSystems");
|
||||
for(unsigned int i = 0; i < damageParticleSystems.size(); ++i) {
|
||||
UnitParticleSystem *ups= damageParticleSystems[i];
|
||||
|
@ -3656,7 +3656,7 @@ void Unit::saveGame(XmlNode *rootNode) {
|
|||
}
|
||||
}
|
||||
// std::map<int, UnitParticleSystem *> damageParticleSystemsInUse;
|
||||
if(damageParticleSystemsInUse.size() > 0) {
|
||||
if(damageParticleSystemsInUse.empty() == false) {
|
||||
XmlNode *damageParticleSystemsInUseNode = unitNode->addChild("damageParticleSystemsInUse");
|
||||
|
||||
for(std::map<int, UnitParticleSystem *>::const_iterator iterMap = damageParticleSystemsInUse.begin();
|
||||
|
@ -3671,7 +3671,7 @@ void Unit::saveGame(XmlNode *rootNode) {
|
|||
}
|
||||
|
||||
// vector<ParticleSystem*> fireParticleSystems;
|
||||
if(fireParticleSystems.size() > 0) {
|
||||
if(fireParticleSystems.empty() == false) {
|
||||
XmlNode *fireParticleSystemsNode = unitNode->addChild("fireParticleSystems");
|
||||
for(unsigned int i = 0; i < fireParticleSystems.size(); ++i) {
|
||||
ParticleSystem *ps= fireParticleSystems[i];
|
||||
|
@ -3682,7 +3682,7 @@ void Unit::saveGame(XmlNode *rootNode) {
|
|||
}
|
||||
|
||||
// vector<UnitParticleSystem*> smokeParticleSystems;
|
||||
if(smokeParticleSystems.size() > 0) {
|
||||
if(smokeParticleSystems.empty() == false) {
|
||||
XmlNode *smokeParticleSystemsNode = unitNode->addChild("smokeParticleSystems");
|
||||
for(unsigned int i = 0; i < smokeParticleSystems.size(); ++i) {
|
||||
UnitParticleSystem *ups= smokeParticleSystems[i];
|
||||
|
|
|
@ -154,8 +154,8 @@ string AttackBoost::getDesc() const{
|
|||
Lang &lang= Lang::getInstance();
|
||||
string str= "";
|
||||
string indent=" ";
|
||||
if(enabled){
|
||||
if(boostUnitList.size()>0){
|
||||
if(enabled) {
|
||||
if(boostUnitList.empty() == false) {
|
||||
str+= "\n"+ lang.get("Effects")+":\n";
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ string AttackBoost::getDesc() const{
|
|||
str+= lang.get("AffectedUnitsFromAll") +":\n";
|
||||
}
|
||||
|
||||
if(boostUnitList.size()>0){
|
||||
if(boostUnitList.empty() == false) {
|
||||
for(int i=0; i<boostUnitList.size(); ++i){
|
||||
str+= " "+boostUnitList[i]->getName()+"\n";
|
||||
}
|
||||
|
|
|
@ -430,6 +430,9 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
|
|||
//read header
|
||||
MapFileHeader header;
|
||||
size_t readBytes = fread(&header, sizeof(MapFileHeader), 1, f);
|
||||
if(readBytes != 1) {
|
||||
throw runtime_error("Invalid map header detected for file: " + path);
|
||||
}
|
||||
|
||||
if(next2Power(header.width) != header.width){
|
||||
throw runtime_error("Map width is not a power of 2");
|
||||
|
|
|
@ -2127,7 +2127,7 @@ void World::saveGame(XmlNode *rootNode) {
|
|||
if(techTree != NULL) {
|
||||
techTree->saveGame(worldNode);
|
||||
}
|
||||
worldNode->addAttribute("techTree",techTree->getName(), mapTagReplacements);
|
||||
worldNode->addAttribute("techTree",(techTree != NULL ? techTree->getName() : ""), mapTagReplacements);
|
||||
// TimeFlow timeFlow;
|
||||
timeFlow.saveGame(worldNode);
|
||||
// Scenario scenario;
|
||||
|
|
|
@ -333,6 +333,9 @@ private:
|
|||
MainWindow *mainWindow;
|
||||
|
||||
public:
|
||||
App() : wxApp() {
|
||||
mainWindow = NULL;
|
||||
}
|
||||
virtual bool OnInit();
|
||||
virtual int MainLoop();
|
||||
virtual int OnExit();
|
||||
|
|
|
@ -330,7 +330,7 @@ const char* findFont(const char *firstFontToTry,const char *firstFontFamilyToTry
|
|||
font = strdup(path); \
|
||||
} \
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#1 Searching for font file [%s] result [%s]\n",path,font); \
|
||||
if( !font && fontFamily && strlen(fontFamily) > 0) { \
|
||||
if( !font && fontFamily != NULL && strlen(fontFamily) > 0) { \
|
||||
string fileFound = findFontFamily(font, fontFamily); \
|
||||
if(fileFound != "") { \
|
||||
path = fileFound.c_str(); \
|
||||
|
|
|
@ -226,8 +226,6 @@ void LuaScript::saveGame(XmlNode *rootNode) {
|
|||
}
|
||||
|
||||
void LuaScript::loadGame(const XmlNode *rootNode) {
|
||||
const XmlNode *luaScriptNode = rootNode;
|
||||
|
||||
vector<XmlNode *> luaScriptNodeList = rootNode->getChildList("LuaScript");
|
||||
for(unsigned int i = 0; i < luaScriptNodeList.size(); ++i) {
|
||||
XmlNode *node = luaScriptNodeList[i];
|
||||
|
|
|
@ -617,7 +617,7 @@ pair<bool,time_t> hasCachedFileCRCValue(string crcCacheFile, int32 &value) {
|
|||
time_t refreshDate = 0;
|
||||
int32 crcValue = 0;
|
||||
time_t lastUpdateDate = 0;
|
||||
int res = fscanf(fp,"%ld,%d,%ld",&refreshDate,&crcValue,&lastUpdateDate);
|
||||
int readbytes = fscanf(fp,"%ld,%d,%ld",&refreshDate,&crcValue,&lastUpdateDate);
|
||||
fclose(fp);
|
||||
|
||||
result.second = lastUpdateDate;
|
||||
|
@ -1756,7 +1756,6 @@ string replaceAllBetweenTokens(string& context, const string startToken,
|
|||
const string endToken, const string newText, bool removeTokens) {
|
||||
size_t lookHere = 0;
|
||||
size_t foundHere = 0;
|
||||
size_t foundHereEnd = 0;
|
||||
if((foundHere = context.find(startToken, lookHere)) != string::npos) {
|
||||
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Replacing context [%s] from [%s] to [%s]\n",context.c_str(),from.c_str(),to.c_str());
|
||||
|
||||
|
|
|
@ -2541,7 +2541,6 @@ bool UPNP_Tools::upnp_add_redirect(int ports[2],bool mutexLock) {
|
|||
char externalIP[16] = "";
|
||||
char ext_port_str[16] = "";
|
||||
char int_port_str[16] = "";
|
||||
int r = 0;
|
||||
|
||||
//printf("SERVER SOCKET upnp_add_redirect - START\n");
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] upnp_add_redir(%d : %d)\n",__FILE__,__FUNCTION__,__LINE__,ports[0],ports[1]);
|
||||
|
@ -2571,6 +2570,7 @@ bool UPNP_Tools::upnp_add_redirect(int ports[2],bool mutexLock) {
|
|||
sprintf(ext_port_str, "%d", ports[0]);
|
||||
sprintf(int_port_str, "%d", ports[1]);
|
||||
|
||||
int r = 0;
|
||||
#ifndef MINIUPNPC_VERSION_PRE1_5
|
||||
#ifndef MINIUPNPC_VERSION_PRE1_6
|
||||
r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,ext_port_str, int_port_str, lanaddr, "MegaGlest - www.megaglest.org", "TCP", 0, NULL);
|
||||
|
@ -2785,12 +2785,11 @@ void BroadCastSocketThread::execute() {
|
|||
if(difftime(time(NULL),elapsed) >= 1 && getQuitStatus() == false) {
|
||||
elapsed = time(NULL);
|
||||
|
||||
ssize_t send_res = 0;
|
||||
bool pauseBroadCast = getPauseBroadcast();
|
||||
if(pauseBroadCast == false) {
|
||||
// Broadcast the packet to the subnet
|
||||
//if( sendto( bcfd, buff, sizeof(buff) + 1, 0 , (struct sockaddr *)&bcaddr, sizeof(struct sockaddr_in) ) != sizeof(buff) + 1 )
|
||||
send_res = sendto( bcfd[idx], buff, buffMaxSize, 0 , (struct sockaddr *)&bcLocal[idx], sizeof(struct sockaddr_in) );
|
||||
ssize_t send_res = sendto( bcfd[idx], buff, buffMaxSize, 0 , (struct sockaddr *)&bcLocal[idx], sizeof(struct sockaddr_in) );
|
||||
if( send_res != buffMaxSize ) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Sendto error: %s\n", getLastSocketErrorFormattedText().c_str());
|
||||
}
|
||||
|
|
|
@ -136,7 +136,10 @@ string doubleToStr(double d,int precsion) {
|
|||
}
|
||||
|
||||
bool IsNumeric(const char *p, bool allowNegative) {
|
||||
if(p != NULL && strcmp(p,"-") == 0) {
|
||||
if(p == NULL) {
|
||||
return false;
|
||||
}
|
||||
if(strcmp(p,"-") == 0) {
|
||||
return false;
|
||||
}
|
||||
int index = 0;
|
||||
|
|
Loading…
Reference in New Issue