diff --git a/source/g3d_viewer/main.h b/source/g3d_viewer/main.h index e5744cba..8683c6b1 100644 --- a/source/g3d_viewer/main.h +++ b/source/g3d_viewer/main.h @@ -212,6 +212,9 @@ private: MainWindow *mainWindow; public: + App() : wxApp() { + mainWindow = NULL; + } virtual bool OnInit(); virtual int MainLoop(); virtual int OnExit(); diff --git a/source/g3d_viewer/renderer.h b/source/g3d_viewer/renderer.h index ed58caff..243dd9df 100644 --- a/source/g3d_viewer/renderer.h +++ b/source/g3d_viewer/renderer.h @@ -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); }; diff --git a/source/glest_game/ai/ai.h b/source/glest_game/ai/ai.h index c7bdf93b..00bc9470 100644 --- a/source/glest_game/ai/ai.h +++ b/source/glest_game/ai/ai.h @@ -169,6 +169,7 @@ public: aiInterface = NULL; startLoc = -1; randomMinWarriorsReached = false; + minWarriors = 0; } ~Ai(); diff --git a/source/glest_game/ai/ai_rule.cpp b/source/glest_game/ai/ai_rule.cpp index cd66ff50..c7a908f2 100644 --- a/source/glest_game/ai/ai_rule.cpp +++ b/source/glest_game/ai/ai_rule.cpp @@ -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; } diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index 69b68503..94599f0c 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -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; diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index d7680c25..df2ca842 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -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; } diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 3adc9d10..b7bf5d86 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -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(); diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index e21c4f9c..e75e8d7d 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -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); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 44d7eedb..f9a48657 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -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]=""; diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index 35aec8cc..57c9cc02 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -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(window); if(mainWindow) { diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index 3edda4d4..9ca1a556 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -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(); diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 3249ba2a..c558487c 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -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(); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index a1314be1..18b3bb71 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -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(); diff --git a/source/glest_game/menu/menu_state_load_game.cpp b/source/glest_game/menu/menu_state_load_game.cpp index a4ad309c..28b66baa 100644 --- a/source/glest_game/menu/menu_state_load_game.cpp +++ b/source/glest_game/menu/menu_state_load_game.cpp @@ -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 { diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 59bc7a4c..54520863 100644 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -817,7 +817,7 @@ void ClientInterface::updateKeyframe(int frameCount) { networkCommandListThread->start(); } - bool hasData = getNetworkCommand(frameCount,cachedPendingCommandsIndex); + getNetworkCommand(frameCount,cachedPendingCommandsIndex); } } diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index e72fcbff..32cbb07e 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -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 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 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 damageParticleSystemsInUse; - if(damageParticleSystemsInUse.size() > 0) { + if(damageParticleSystemsInUse.empty() == false) { XmlNode *damageParticleSystemsInUseNode = unitNode->addChild("damageParticleSystemsInUse"); for(std::map::const_iterator iterMap = damageParticleSystemsInUse.begin(); @@ -3671,7 +3671,7 @@ void Unit::saveGame(XmlNode *rootNode) { } // vector 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 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]; diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 2d63c03d..b2e4a738 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -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; igetName()+"\n"; } diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index c7bf7b36..7d439b2c 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -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"); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 8625f9fa..61bb5c60 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -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; diff --git a/source/glest_map_editor/main.h b/source/glest_map_editor/main.h index f2ed333e..4c26ca9a 100644 --- a/source/glest_map_editor/main.h +++ b/source/glest_map_editor/main.h @@ -333,6 +333,9 @@ private: MainWindow *mainWindow; public: + App() : wxApp() { + mainWindow = NULL; + } virtual bool OnInit(); virtual int MainLoop(); virtual int OnExit(); diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index 8639d06e..19c20025 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -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(); \ diff --git a/source/shared_lib/sources/lua/lua_script.cpp b/source/shared_lib/sources/lua/lua_script.cpp index 6e004647..b8d4d785 100644 --- a/source/shared_lib/sources/lua/lua_script.cpp +++ b/source/shared_lib/sources/lua/lua_script.cpp @@ -226,8 +226,6 @@ void LuaScript::saveGame(XmlNode *rootNode) { } void LuaScript::loadGame(const XmlNode *rootNode) { - const XmlNode *luaScriptNode = rootNode; - vector luaScriptNodeList = rootNode->getChildList("LuaScript"); for(unsigned int i = 0; i < luaScriptNodeList.size(); ++i) { XmlNode *node = luaScriptNodeList[i]; diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index f07353d0..d5b2f958 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -617,7 +617,7 @@ pair 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()); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index bd6120bb..f58ee796 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -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()); } diff --git a/source/shared_lib/sources/util/conversion.cpp b/source/shared_lib/sources/util/conversion.cpp index a2704c1c..f608c86f 100644 --- a/source/shared_lib/sources/util/conversion.cpp +++ b/source/shared_lib/sources/util/conversion.cpp @@ -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;