From 63e6c2b2872abb1ef6f68ba7664d7bfb9574c3b8 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 21 Nov 2015 15:45:57 +0100 Subject: [PATCH] Get rid of false positive warnings from cppcheck. --- src/CEngine.cpp | 6 ++---- src/CPak.cpp | 10 +++++----- src/loadSave.cpp | 10 +++++----- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/CEngine.cpp b/src/CEngine.cpp index ac9bb8c..d99bb0a 100644 --- a/src/CEngine.cpp +++ b/src/CEngine.cpp @@ -393,14 +393,12 @@ bool Engine::unpack(const char *filename, int fileType) snprintf(tempPath, sizeof tempPath, "%smusic.mod", userHomeDirectory); fp = fopen(tempPath, "wb"); } - - if (fileType == PAK_TAGS) + else if (fileType == PAK_TAGS) { snprintf(tempPath, sizeof tempPath, "%smusic.tags", userHomeDirectory); fp = fopen(tempPath, "wb"); } - - if (fileType == PAK_FONT) + else if (fileType == PAK_FONT) { snprintf(tempPath, sizeof tempPath, "%sfont.ttf", userHomeDirectory); fp = fopen(tempPath, "wb"); diff --git a/src/CPak.cpp b/src/CPak.cpp index 7427df3..6eba5ce 100644 --- a/src/CPak.cpp +++ b/src/CPak.cpp @@ -63,19 +63,19 @@ void Pak::setPakFile(const char *pakFilename) if (!pak) { - showPakErrorAndExit(); + return showPakErrorAndExit(); } fseek(pak, (-sizeof(Uint32)) * 2, SEEK_END); if (fread(&listPos, sizeof(Uint32), 1, pak) != 1) { fclose(pak); - showPakErrorAndExit(); + return showPakErrorAndExit(); } if (fread(&numberOfFiles, sizeof(Uint32), 1, pak) != 1) { fclose(pak); - showPakErrorAndExit(); + return showPakErrorAndExit(); } debug(("Pak : File list resides at %d\n", (int)listPos)); @@ -94,7 +94,7 @@ void Pak::setPakFile(const char *pakFilename) if (!result) { fclose(pak); - showPakErrorAndExit(); + return showPakErrorAndExit(); } debug(("Read FileData #%d / %d : %s\n", (i + 1), numberOfFiles, fd[i].filename)); @@ -144,7 +144,7 @@ bool Pak::unpack(const char *filename, unsigned char **buffer) if (fread(input, 1, currentFile->cSize, pak) != currentFile->cSize) { fclose(pak); - showPakErrorAndExit(); + return showPakErrorAndExit(), false; } uLongf fSize = (uLongf)currentFile->fSize; diff --git a/src/loadSave.cpp b/src/loadSave.cpp index a9eb85c..3dfc2e1 100644 --- a/src/loadSave.cpp +++ b/src/loadSave.cpp @@ -107,7 +107,7 @@ bool loadGame(int slot) if (fread(&game, sizeof(Game), 1, fp) != 1) { fclose(fp); - graphics.showErrorAndExit("The save data loaded was not in the format expected", ""); + return graphics.showErrorAndExit("The save data loaded was not in the format expected", ""), false; } fclose(fp); @@ -125,7 +125,7 @@ bool loadGame(int slot) { if (!fgets(line, 1024, fp)) { fclose(fp); - graphics.showErrorAndExit("Unexpected end of file reading save data", ""); + return graphics.showErrorAndExit("Unexpected end of file reading save data", ""), false; } sscanf(line, "%*c %[^\"] %*c %*c %[^\"] %*c %d %d", string[0], string[1], ¶m[0], ¶m[1]); @@ -356,13 +356,13 @@ void saveGame() if (!fp) { - graphics.showErrorAndExit("File write error whilst saving game", ""); + return graphics.showErrorAndExit("File write error whilst saving game", ""); } if (fwrite(&game, sizeof(Game), 1, fp) != 1) { fclose(fp); - graphics.showErrorAndExit("File write error whilst saving game", strerror(errno)); + return graphics.showErrorAndExit("File write error whilst saving game", strerror(errno)); } fclose(fp); @@ -373,7 +373,7 @@ void saveGame() if (!fp) { - graphics.showErrorAndExit("File write error whilst saving game", ""); + return graphics.showErrorAndExit("File write error whilst saving game", ""); } createPersistantMapData(); -- 2.39.5