From: Nicola Spanti (RyDroid) Date: Tue, 20 Dec 2016 00:26:42 +0000 (+0100) Subject: Fixing some warnings of cppcheck X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=cf610b0dfbf15ffafaefcae72a44957095fd7740;p=lugaru.git Fixing some warnings of cppcheck cppcheck --quiet --enable=warning,style,performance,portability Source/ --- diff --git a/Source/Animation/Skeleton.cpp b/Source/Animation/Skeleton.cpp index 014117c..191f3cf 100644 --- a/Source/Animation/Skeleton.cpp +++ b/Source/Animation/Skeleton.cpp @@ -107,7 +107,6 @@ void Skeleton::FindForwards() */ float Skeleton::DoConstraints(XYZ *coords, float *scale) { - float friction = 1.5; const float elasticity = .3; XYZ bounceness; const int numrepeats = 3; @@ -230,6 +229,7 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) muscles[i].DoConstraint(spinny); } + float friction; for (i = 0; i < joints.size(); i++) { //Length constraints //Ground constraint diff --git a/Source/Devtools/ConsoleCmds.cpp b/Source/Devtools/ConsoleCmds.cpp index 57e9f4a..1453364 100644 --- a/Source/Devtools/ConsoleCmds.cpp +++ b/Source/Devtools/ConsoleCmds.cpp @@ -524,8 +524,8 @@ void ch_type(const char *args) void ch_path(const char *args) { - int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]); - for (int i = 0; i < n; i++) + unsigned int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]); + for (unsigned int i = 0; i < n; i++) if (stripfx(args, pathtypenames[i])) { editorpathtype = i; break; diff --git a/Source/Environment/Terrain.cpp b/Source/Environment/Terrain.cpp index ba4e240..e85b71f 100644 --- a/Source/Environment/Terrain.cpp +++ b/Source/Environment/Terrain.cpp @@ -1127,14 +1127,12 @@ void Terrain::drawdecals() void Terrain::AddObject(XYZ where, float radius, int id) { - bool done; - int i, j; XYZ points[4]; if (id >= 0 && id < 10000) - for (i = 0; i < subdivision; i++) { - for (j = 0; j < subdivision; j++) { + for (int i = 0; i < subdivision; i++) { + for (int j = 0; j < subdivision; j++) { if (patchobjectnum[i][j] < 300 - 1) { - done = 0; + bool done = false; points[0].x = (size / subdivision) * i; points[0].z = (size / subdivision) * j; points[0].y = heightmap[(int)points[0].x][(int)points[0].z]; diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index d14a077..7b195df 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -119,8 +119,6 @@ int Game::DrawGLScene(StereoSide side) static float tempmult; float tutorialopac; std::string string; - std::string string2; - std::string string3; static int drawmode = 0; if ( stereomode == stereoAnaglyph ) { @@ -137,7 +135,8 @@ int Game::DrawGLScene(StereoSide side) } else { glColorMask( 1.0, 1.0, 1.0, 1.0 ); - if ( stereomode == stereoHorizontalInterlaced || stereomode == stereoVerticalInterlaced ) { + if ( stereomode == stereoHorizontalInterlaced || + stereomode == stereoVerticalInterlaced ) { glStencilFunc(side == stereoLeft ? GL_NOTEQUAL : GL_EQUAL, 0x01, 0x01); } } @@ -583,10 +582,9 @@ int Game::DrawGLScene(StereoSide side) //Hot spots if (Hotspot::hotspots.size() && (bonustime >= 1 || bonus <= 0 || bonustime < 0) && !Tutorial::active) { float closestdist = -1; - float distance = 0; int closest = Hotspot::current; for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) { - distance = distsq(&Person::players[0]->coords, &Hotspot::hotspots[i].position); + float distance = distsq(&Person::players[0]->coords, &Hotspot::hotspots[i].position); if (closestdist == -1 || distance < closestdist) { if (distsq(&Person::players[0]->coords, &Hotspot::hotspots[i].position) < Hotspot::hotspots[i].size && ((Hotspot::hotspots[i].type <= 10 && Hotspot::hotspots[i].type >= 0) || (Hotspot::hotspots[i].type <= 40 && Hotspot::hotspots[i].type >= 20))) { closestdist = distance; diff --git a/Source/Objects/Person.cpp b/Source/Objects/Person.cpp index 36328a4..063f40f 100644 --- a/Source/Objects/Person.cpp +++ b/Source/Objects/Person.cpp @@ -6861,17 +6861,16 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, int findPathDist(int start, int end) { - int smallestcount, count, connected; - int last, last2, last3, last4; + int smallestcount, connected; int closest; smallestcount = 1000; - for (int i = 0; i < 50; i++) { - count = 0; - last = start; - last2 = -1; - last3 = -1; - last4 = -1; + for (char i = 0; i < 50; i++) { + unsigned count = 0; + int last = start; + int last2 = -1; + int last3 = -1; + int last4 = -1; while (last != end && count < 30) { closest = -1; for (int j = 0; j < Game::numpathpoints; j++) { diff --git a/Source/Utils/Folders.cpp b/Source/Utils/Folders.cpp index 8de69db..21322c1 100644 --- a/Source/Utils/Folders.cpp +++ b/Source/Utils/Folders.cpp @@ -84,7 +84,7 @@ std::string Folders::getConfigFilePath() #if PLATFORM_LINUX /* Generic code for XDG ENVVAR test and fallback */ -std::string Folders::getGenericDirectory(const char* ENVVAR, const std::string fallback) { +std::string Folders::getGenericDirectory(const char* ENVVAR, const std::string& fallback) { const char* path = getenv(ENVVAR); std::string ret; if ((path != NULL) && (strlen(path) != 0)) { @@ -114,30 +114,18 @@ const char* Folders::getHomeDirectory() } #endif -bool Folders::makeDirectory(std::string path) { +bool Folders::makeDirectory(const std::string& path) { #ifdef _WIN32 int status = CreateDirectory(path.c_str(), NULL); - if (status != 0) { - return true; - } else if(GetLastError() == ERROR_ALREADY_EXISTS) { - return true; - } else { - return false; - } + return status != 0 || GetLastError() == ERROR_ALREADY_EXISTS; #else errno = 0; int status = mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - if (status == 0) { - return true; - } else if(errno == EEXIST) { - return true; - } else { - return false; - } + return status == 0 || errno == EEXIST; #endif } -FILE* Folders::openMandatoryFile(std::string filename, const char* mode) +FILE* Folders::openMandatoryFile(const std::string& filename, const char* mode) { FILE* tfile = fopen(filename.c_str(), mode); if (tfile == NULL) { diff --git a/Source/Utils/Folders.hpp b/Source/Utils/Folders.hpp index 9d52c49..9ecf9e0 100644 --- a/Source/Utils/Folders.hpp +++ b/Source/Utils/Folders.hpp @@ -30,9 +30,10 @@ along with Lugaru. If not, see . struct FileNotFoundException: public std::exception { std::string errorText; - FileNotFoundException (const std::string& filename) { - errorText = filename + " could not be found"; - } + + FileNotFoundException (const std::string& filename) + : errorText(filename + " could not be found") + {} const char * what () const throw () { return errorText.c_str(); @@ -44,27 +45,29 @@ class Folders static const std::string dataDir; public: - /* Returns path to the screenshot directory. Creates it if needed. */ + /** Returns path to the screenshot directory. Creates it if needed. */ static std::string getScreenshotDir(); - /* Returns full path for user data */ + /** Returns full path for user data */ static std::string getUserDataPath(); - /* Returns full path for config file */ + /** Returns full path for config file */ static std::string getConfigFilePath(); - static FILE* openMandatoryFile(std::string filename, const char* mode); + static FILE* openMandatoryFile(const std::string& filename, const char* mode); /* Returns full path for a game resource */ - static inline std::string getResourcePath(std::string filepath) { return dataDir + '/' + filepath; } + static inline std::string getResourcePath(const std::string& filepath) + { return dataDir + '/' + filepath; } - /* Returns full path for user progress save */ - static inline std::string getUserSavePath() { return getUserDataPath() + "/users"; } + /** Returns full path for user progress save */ + static inline std::string getUserSavePath() + { return getUserDataPath() + "/users"; } private: static const char* getHomeDirectory(); - static std::string getGenericDirectory(const char* ENVVAR, const std::string fallback); - static bool makeDirectory(std::string path); + static std::string getGenericDirectory(const char* ENVVAR, const std::string& fallback); + static bool makeDirectory(const std::string& path); }; #endif /* _FOLDERS_H_ */