From e86cb3aeff2d10566a2229414abf7c37d86343c0 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 18 Oct 2012 08:16:47 +0000 Subject: [PATCH] - more code cleanup based on suggestions from cppcheck --- source/glest_game/game/game.cpp | 2 +- source/glest_game/game/script_manager.cpp | 8 +++---- source/glest_game/gui/selection.cpp | 1 - source/glest_game/menu/menu_state_options.cpp | 1 - .../include/platform/common/platform_common.h | 2 +- .../include/platform/sdl/platform_util.h | 2 +- .../sources/feathery_ftp/ftpSession.c | 3 +-- .../graphics/gl/font_text_freetypegl.cpp | 8 +++---- source/shared_lib/sources/graphics/model.cpp | 4 ++-- source/shared_lib/sources/lua/lua_script.cpp | 6 ++--- .../sources/platform/common/base_thread.cpp | 24 +++++++++---------- .../platform/common/platform_common.cpp | 22 +++++++++++++---- .../platform/common/simple_threads.cpp | 8 +++---- .../sources/platform/posix/socket.cpp | 8 +++---- .../sources/platform/win32/platform_util.cpp | 2 +- source/shared_lib/sources/util/properties.cpp | 18 +++++++------- 16 files changed, 63 insertions(+), 56 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index fa6322c7..f00baa48 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -585,7 +585,7 @@ string Game::extractFactionLogoFile(bool &loadingImageUsed, string factionName, string linkedCurrentPath = techTreePath + "factions/" + factionName; endPathWithSlash(linkedCurrentPath); - string linkedTmppath= linkedCurrentPath + factionName +".xml"; + //string linkedTmppath= linkedCurrentPath + factionName +".xml"; path = linkedCurrentPath; if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] possible loading screen dir '%s'\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str()); diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index 5c62df9c..250bfbc2 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -445,11 +445,11 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro } } catch(const megaglest_runtime_error &ex) { - string sErrBuf = ""; + //string sErrBuf = ""; //if(ex.wantStackTrace() == true) { - char szErrBuf[8096]=""; - sprintf(szErrBuf,"In [%s::%s %d]",__FILE__,__FUNCTION__,__LINE__); - sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + char szErrBuf[8096]=""; + sprintf(szErrBuf,"In [%s::%s %d]",__FILE__,__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); //} SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); diff --git a/source/glest_game/gui/selection.cpp b/source/glest_game/gui/selection.cpp index 609fc534..c48524f7 100644 --- a/source/glest_game/gui/selection.cpp +++ b/source/glest_game/gui/selection.cpp @@ -197,7 +197,6 @@ void Selection::addUnitToGroup(int groupIndex,Unit *unit) { } if(unit != NULL) { - const UnitContainer &addUnits = selectedUnits; groups[groupIndex].push_back(unit); } } diff --git a/source/glest_game/menu/menu_state_options.cpp b/source/glest_game/menu/menu_state_options.cpp index c05fb92c..4475261f 100644 --- a/source/glest_game/menu/menu_state_options.cpp +++ b/source/glest_game/menu/menu_state_options.cpp @@ -724,7 +724,6 @@ void MenuStateOptions::reloadUI() { labelNetworkSettings.setText(lang.get("Network")); labelServerPortLabel.setText(lang.get("ServerPort")); - Config &config= Config::getInstance(); labelPublishServerExternalPort.setText(lang.get("PublishServerExternalPort")); diff --git a/source/shared_lib/include/platform/common/platform_common.h b/source/shared_lib/include/platform/common/platform_common.h index a0b7fcf3..89432626 100644 --- a/source/shared_lib/include/platform/common/platform_common.h +++ b/source/shared_lib/include/platform/common/platform_common.h @@ -229,7 +229,7 @@ vector replaceAllBetweenTokens(vector& context, const string &startT string replaceAllBetweenTokens(string& context, const string &startToken, const string &endToken, const string &newText, bool removeTokens=true); bool removeFile(string file); bool renameFile(string oldFile, string newFile); -void removeFolder(const string path); +void removeFolder(const string &path); off_t getFileSize(string filename); bool searchAndReplaceTextInFile(string fileName, string findText, string replaceText, bool simulateOnly); void copyFileTo(string fromFileName, string toFileName); diff --git a/source/shared_lib/include/platform/sdl/platform_util.h b/source/shared_lib/include/platform/sdl/platform_util.h index d4d547cf..7006fc46 100644 --- a/source/shared_lib/include/platform/sdl/platform_util.h +++ b/source/shared_lib/include/platform/sdl/platform_util.h @@ -94,7 +94,7 @@ LONG WINAPI UnhandledExceptionFilter2(struct _EXCEPTION_POINTERS *ExceptionInfo) // Misc // ===================================================== LPWSTR Ansi2WideString(LPCSTR lpaszString); -std::string utf8_encode(const std::wstring wstr); +std::string utf8_encode(const std::wstring &wstr); std::wstring utf8_decode(const std::string &str); std::string getRegKey(const std::string& location, const std::string& name); diff --git a/source/shared_lib/sources/feathery_ftp/ftpSession.c b/source/shared_lib/sources/feathery_ftp/ftpSession.c index 75cab7e0..1bfea53f 100644 --- a/source/shared_lib/sources/feathery_ftp/ftpSession.c +++ b/source/shared_lib/sources/feathery_ftp/ftpSession.c @@ -183,9 +183,8 @@ ftpSession_S* ftpGetSession(int id) LOCAL int normalizePath(char* path) { char *in; - char *r = NULL; + char *r = path; - r = path; in = path; while((in = strchr(in, '/'))) diff --git a/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp b/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp index 99e5cb68..00195099 100644 --- a/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp +++ b/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp @@ -224,10 +224,10 @@ float TextFreetypeGL::LineHeight(const char* str, const int len) { //Font::scaleFontValueCenterHFactor = 30.0; //Font::scaleFontValue = 1.0; - float result = 0; + //float result = 0; //result = font->height - font->linegap; - result = font->ascender - font->descender - font->linegap; + float result = font->ascender - font->descender - font->linegap; //printf("#2 LineHeight [%s] height = %f linegap = %f ascender = %f descender = %f\n",str,font->height,font->linegap,font->ascender,font->descender); //result += (result * Font::scaleFontValue); @@ -260,9 +260,9 @@ float TextFreetypeGL::LineHeight(const char* str, const int len) { float TextFreetypeGL::LineHeight(const wchar_t* str, const int len) { //Font::scaleFontValueCenterHFactor = 2.0; - float result = 0; + //float result = 0; - result = font->height - font->linegap; + float result = font->height - font->linegap; // if(wcslen(str) > 0) { // TextureGlyph *glyph = texture_font_get_glyph( font, str[0] ); diff --git a/source/shared_lib/sources/graphics/model.cpp b/source/shared_lib/sources/graphics/model.cpp index 59f28765..064e9380 100644 --- a/source/shared_lib/sources/graphics/model.cpp +++ b/source/shared_lib/sources/graphics/model.cpp @@ -1134,11 +1134,11 @@ void BaseColorPickEntity::init(int bufferSize) { } string BaseColorPickEntity::getColorDescription() const { - string result = ""; + //string result = ""; char szBuf[100]=""; //sprintf(szBuf,"%d.%d.%d.%d",uniqueColorID[0],uniqueColorID[1],uniqueColorID[2],uniqueColorID[3]); sprintf(szBuf,"%d.%d.%d",uniqueColorID[0],uniqueColorID[1],uniqueColorID[2]); - result = szBuf; + string result = szBuf; return result; } diff --git a/source/shared_lib/sources/lua/lua_script.cpp b/source/shared_lib/sources/lua/lua_script.cpp index fc665792..7d7bcff0 100644 --- a/source/shared_lib/sources/lua/lua_script.cpp +++ b/source/shared_lib/sources/lua/lua_script.cpp @@ -977,11 +977,11 @@ string LuaArguments::getStackText() const { } else if(lua_istable(luaState, -i)){ - int tableLen = 0; + //int tableLen = 0; #if LUA_VERSION_NUM > 501 - tableLen = lua_rawlen(luaState, -i); + int tableLen = lua_rawlen(luaState, -i); #else - tableLen = luaL_getn(luaState, -i); + int tableLen = luaL_getn(luaState, -i); #endif stackString+= "Table (" + intToStr(tableLen) + ")\n"; // for(unsigned int j = 1; j < tableLen; ++j) { diff --git a/source/shared_lib/sources/platform/common/base_thread.cpp b/source/shared_lib/sources/platform/common/base_thread.cpp index 110d2590..4ed64576 100644 --- a/source/shared_lib/sources/platform/common/base_thread.cpp +++ b/source/shared_lib/sources/platform/common/base_thread.cpp @@ -88,11 +88,11 @@ void BaseThread::setThreadOwnerValid(bool value) { } bool BaseThread::getThreadOwnerValid() { - bool ret = false; + //bool ret = false; static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexThreadOwnerValid,mutexOwnerId); //mutexThreadOwnerValid.setOwnerId(mutexOwnerId); - ret = threadOwnerValid; + bool ret = threadOwnerValid; safeMutex.ReleaseLock(); return ret; @@ -115,22 +115,22 @@ void BaseThread::setQuitStatus(bool value) { } bool BaseThread::getQuitStatus() { - bool retval = false; + //bool retval = false; static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexQuit,mutexOwnerId); //mutexQuit.setOwnerId(mutexOwnerId); - retval = quit; + bool retval = quit; safeMutex.ReleaseLock(); return retval; } bool BaseThread::getHasBeginExecution() { - bool retval = false; + //bool retval = false; static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexBeginExecution,mutexOwnerId); //mutexBeginExecution.setOwnerId(mutexOwnerId); - retval = hasBeginExecution; + bool retval = hasBeginExecution; safeMutex.ReleaseLock(); return retval; @@ -149,11 +149,11 @@ void BaseThread::setHasBeginExecution(bool value) { } bool BaseThread::getRunningStatus() { - bool retval = false; + //bool retval = false; static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexRunning,mutexOwnerId); - retval = running; + bool retval = running; safeMutex.ReleaseLock(); if(retval == false) { @@ -183,20 +183,20 @@ void BaseThread::setExecutingTask(bool value) { } bool BaseThread::getExecutingTask() { - bool retval = false; + //bool retval = false; static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexExecutingTask,mutexOwnerId); - retval = executingTask; + bool retval = executingTask; safeMutex.ReleaseLock(); return retval; } bool BaseThread::getDeleteSelfOnExecutionDone() { - bool retval = false; + //bool retval = false; static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexDeleteSelfOnExecutionDone,mutexOwnerId); - retval = deleteSelfOnExecutionDone; + bool retval = deleteSelfOnExecutionDone; safeMutex.ReleaseLock(); return retval; diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 655faea6..a25c5ddb 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -443,7 +443,7 @@ bool fileExists(const string &path) { return false; } -void removeFolder(const string path) { +void removeFolder(const string &path) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); string deletePath = path; @@ -1433,9 +1433,15 @@ void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight,bo if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); /* Get available fullscreen/hardware modes */ - int flags = SDL_RESIZABLE; + #if defined(WIN32) || defined(__APPLE__) - flags = 0; + + int flags = 0; + + #else + + int flags = SDL_RESIZABLE; + #endif if(isFullscreen) flags = SDL_FULLSCREEN; SDL_Rect**modes = SDL_ListModes(NULL, SDL_OPENGL|flags); @@ -1528,9 +1534,15 @@ void getFullscreenVideoModes(vector *modeinfos, bool isFullscreen) { /* Get available fullscreen/hardware modes */ //SDL_Rect**modes = SDL_ListModes(NULL, SDL_OPENGL|SDL_RESIZABLE); - int flags = SDL_RESIZABLE; + #if defined(WIN32) || defined(__APPLE__) - flags = 0; + + int flags = 0; + + #else + + int flags = SDL_RESIZABLE; + #endif if(isFullscreen) flags = SDL_FULLSCREEN; SDL_Rect**modes = SDL_ListModes(&format, SDL_OPENGL|flags); diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp index 6e22c9a4..ca97c326 100644 --- a/source/shared_lib/sources/platform/common/simple_threads.cpp +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -389,12 +389,12 @@ void SimpleTaskThread::setOverrideShutdownTask(taskFunctionCallback *ptr) { } bool SimpleTaskThread::isThreadExecutionLagging() { - bool result = false; + //bool result = false; //static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,mutexOwnerId); mutexLastExecuteTimestamp.setOwnerId(mutexOwnerId); - result = (difftime(time(NULL),lastExecuteTimestamp) >= 5.0); + bool result = (difftime(time(NULL),lastExecuteTimestamp) >= 5.0); safeMutex.ReleaseLock(); return result; @@ -507,12 +507,12 @@ void SimpleTaskThread::setTaskSignalled(bool value) { } bool SimpleTaskThread::getTaskSignalled() { - bool retval = false; + //bool retval = false; //static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexTaskSignaller,mutexOwnerId); mutexTaskSignaller.setOwnerId(mutexOwnerId); - retval = taskSignalled; + bool retval = taskSignalled; safeMutex.ReleaseLock(); return retval; diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index af98ac8d..fae4c6f1 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -2592,15 +2592,15 @@ 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; + //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); + int r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,ext_port_str, int_port_str, lanaddr, "MegaGlest - www.megaglest.org", "TCP", 0, NULL); #else - r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,ext_port_str, int_port_str, lanaddr, "MegaGlest - www.megaglest.org", "TCP", 0); + int r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,ext_port_str, int_port_str, lanaddr, "MegaGlest - www.megaglest.org", "TCP", 0); #endif #else - r = UPNP_AddPortMapping(urls.controlURL, data.servicetype,ext_port_str, int_port_str, lanaddr, "MegaGlest - www.megaglest.org", "TCP", 0); + int r = UPNP_AddPortMapping(urls.controlURL, data.servicetype,ext_port_str, int_port_str, lanaddr, "MegaGlest - www.megaglest.org", "TCP", 0); #endif if (r != UPNPCOMMAND_SUCCESS) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] AddPortMapping(%s, %s, %s) failed\n",__FILE__,__FUNCTION__,__LINE__,ext_port_str, int_port_str, lanaddr); diff --git a/source/shared_lib/sources/platform/win32/platform_util.cpp b/source/shared_lib/sources/platform/win32/platform_util.cpp index 632bc105..4dc3922c 100644 --- a/source/shared_lib/sources/platform/win32/platform_util.cpp +++ b/source/shared_lib/sources/platform/win32/platform_util.cpp @@ -54,7 +54,7 @@ LPWSTR Ansi2WideString(LPCSTR lpaszString) { } // Convert a wide Unicode string to an UTF8 string -std::string utf8_encode(const std::wstring wstr) { +std::string utf8_encode(const std::wstring &wstr) { int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); std::string strTo( size_needed, 0 ); WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index 8b4d7935..d81d4caa 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -167,11 +167,10 @@ std::map Properties::getTagReplacementValues(std::map Properties::getTagReplacementValues(std::map *mapTag } } else { - char *homeDir = NULL; #ifdef WIN32 - homeDir = getenv("USERPROFILE"); + char *homeDir = getenv("USERPROFILE"); #else - homeDir = getenv("HOME"); + char *homeDir = getenv("HOME"); #endif replaceAll(value, "~/", (homeDir != NULL ? homeDir : "")); @@ -293,8 +291,8 @@ bool Properties::applyTagsToValue(string &value, std::map *mapTag } #endif - char *username = NULL; - username = getenv("USERNAME"); + //char *username = NULL; + char *username = getenv("USERNAME"); replaceAll(value, "$USERNAME", (username != NULL ? username : "")); replaceAll(value, "%%USERNAME%%", (username != NULL ? username : "")); replaceAll(value, "{USERNAME}", (username != NULL ? username : ""));