summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-03-11 21:39:42 +0300
committerAndrei Karas <akaras@inbox.ru>2017-03-11 21:39:42 +0300
commita721e4898f71a68ecb916940864599d462880e5b (patch)
tree50442e8b86707221f498ea0f304a5314a0e67430 /src
parent81b97b30afa0c72e5ff17162c7d1fa88dd6187fb (diff)
downloadplus-a721e4898f71a68ecb916940864599d462880e5b.tar.gz
plus-a721e4898f71a68ecb916940864599d462880e5b.tar.bz2
plus-a721e4898f71a68ecb916940864599d462880e5b.tar.xz
plus-a721e4898f71a68ecb916940864599d462880e5b.zip
Fix different issues found by automatic checks.
Diffstat (limited to 'src')
-rw-r--r--src/dyetool/client.cpp2
-rw-r--r--src/fs/files.cpp2
-rw-r--r--src/fs/paths.cpp14
-rw-r--r--src/fs/physfs/virtfsphys.h5
-rw-r--r--src/fs/physfs/virtfsphys_unittest.cc1
-rw-r--r--src/fs/virtfs/fileapi.h2
-rw-r--r--src/fs/virtfs/virtfileprivate.cpp4
-rw-r--r--src/fs/virtfs/virtfs.cpp6
-rw-r--r--src/fs/virtfs/virtfs_unittest.cc6
-rw-r--r--src/fs/virtfs/virtfsdir.cpp3
-rw-r--r--src/fs/virtfs/virtfsdir.h3
-rw-r--r--src/fs/virtfs/virtfszip.cpp5
-rw-r--r--src/fs/virtfs/virtfszip.h3
-rw-r--r--src/fs/virtfs/virtzipentry.cpp3
-rw-r--r--src/fs/virtfs/zip.cpp2
-rw-r--r--src/fs/virtfs/zip.h1
-rw-r--r--src/fs/virtfs/ziplocalheader.cpp2
-rw-r--r--src/fs/virtfs_unittest.cc3
-rw-r--r--src/fs/virtfsfuncs.h11
-rw-r--r--src/fs/virtfstools.cpp5
-rw-r--r--src/gui/viewport.cpp2
-rw-r--r--src/integrity_unittest.cc6
-rw-r--r--src/maingui.cpp3
-rw-r--r--src/resources/resourcemanager/resourcemanager_unittest.cc1
24 files changed, 38 insertions, 57 deletions
diff --git a/src/dyetool/client.cpp b/src/dyetool/client.cpp
index b7ffd63ed..6ffa4b048 100644
--- a/src/dyetool/client.cpp
+++ b/src/dyetool/client.cpp
@@ -42,8 +42,8 @@
#include "gui/widgets/button.h"
#include "gui/widgets/createwidget.h"
#include "gui/widgets/desktop.h"
-#include "gui/widgets/windowcontainer.h"
#include "gui/widgets/window.h"
+#include "gui/widgets/windowcontainer.h"
#include "input/inputmanager.h"
#include "input/joystick.h"
diff --git a/src/fs/files.cpp b/src/fs/files.cpp
index 6c4792270..b53228ab1 100644
--- a/src/fs/files.cpp
+++ b/src/fs/files.cpp
@@ -190,7 +190,7 @@ int Files::copyFile(const std::string &restrict srcName,
return -1;
}
- const int chunkSize = 500000;
+ const int chunkSize = 512000;
char *buf = new char[chunkSize];
size_t sz = 0;
while ((sz = fread(buf, 1, chunkSize, srcFile)))
diff --git a/src/fs/paths.cpp b/src/fs/paths.cpp
index 06e87c2f0..050b9d00c 100644
--- a/src/fs/paths.cpp
+++ b/src/fs/paths.cpp
@@ -78,11 +78,11 @@ std::string getRealPath(const std::string &str)
// defined(__native_client__)
char *realPath = realpath(str.c_str(), nullptr);
+ if (!realPath)
+ return "";
#endif // defined(__OpenBSD__) || defined(__ANDROID__) ||
// defined(__native_client__)
- if (!realPath)
- return "";
std::string path = realPath;
free(realPath);
return path;
@@ -105,7 +105,7 @@ bool checkPath(const std::string &path)
void prepareFsPath(std::string &path)
{
- std::string path2 = path;
+// std::string path2 = path;
sanitizePath(path);
// can be enabled for debugging
// if (path != path2)
@@ -231,11 +231,9 @@ std::string getHomePath()
const char *path = getenv("HOME");
if (path == nullptr)
{
- uid_t uid = getuid();
- struct passwd *pw;
-
- pw = getpwuid(uid);
- if (pw != NULL &&
+ const uid_t uid = getuid();
+ const struct passwd *const pw = getpwuid(uid);
+ if (pw != nullptr &&
pw->pw_dir != nullptr)
{
path = pw->pw_dir;
diff --git a/src/fs/physfs/virtfsphys.h b/src/fs/physfs/virtfsphys.h
index 97b70aae6..1daebfb4f 100644
--- a/src/fs/physfs/virtfsphys.h
+++ b/src/fs/physfs/virtfsphys.h
@@ -18,10 +18,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifdef USE_PHYSFS
#ifndef UTILS_VIRTFSPHYS_H
#define UTILS_VIRTFSPHYS_H
+#ifdef USE_PHYSFS
+
#include "enums/simpletypes/append.h"
#include "localconsts.h"
@@ -78,5 +79,5 @@ namespace VirtFsPhys
int eof(VirtFile *restrict const file);
} // namespace VirtFsPhys
-#endif // UTILS_VIRTFSPHYS_H
#endif // USE_PHYSFS
+#endif // UTILS_VIRTFSPHYS_H
diff --git a/src/fs/physfs/virtfsphys_unittest.cc b/src/fs/physfs/virtfsphys_unittest.cc
index 429579b05..636d67a91 100644
--- a/src/fs/physfs/virtfsphys_unittest.cc
+++ b/src/fs/physfs/virtfsphys_unittest.cc
@@ -184,7 +184,6 @@ TEST_CASE("VirtFsPhys enumerateFiles2")
VirtList *list = nullptr;
list = VirtFsPhys::enumerateFiles("/");
- const size_t sz = list->names.size();
REQUIRE(list->names.size() == 5);
VirtFsPhys::freeList(list);
diff --git a/src/fs/virtfs/fileapi.h b/src/fs/virtfs/fileapi.h
index 7654e06d4..121506816 100644
--- a/src/fs/virtfs/fileapi.h
+++ b/src/fs/virtfs/fileapi.h
@@ -22,6 +22,8 @@
#define UTILS_VIRTFS_FILEAPI_H
#ifndef USE_PHYSFS
+#include "localconsts.h"
+
#ifdef USE_FILE_FOPEN
#define FILEHTYPE FILE *const
#define FILEMTYPE char *
diff --git a/src/fs/virtfs/virtfileprivate.cpp b/src/fs/virtfs/virtfileprivate.cpp
index 682992c68..5baadbc15 100644
--- a/src/fs/virtfs/virtfileprivate.cpp
+++ b/src/fs/virtfs/virtfileprivate.cpp
@@ -22,7 +22,6 @@
#include "fs/virtfs/virtfileprivate.h"
#include <unistd.h>
-#include <zlib.h>
#include "debug.h"
@@ -55,7 +54,6 @@ VirtFilePrivate::~VirtFilePrivate()
{
if (mFd != FILEHDEFAULT)
FILECLOSE(mFd);
- if (mBuf)
- delete [] mBuf;
+ delete [] mBuf;
}
#endif // USE_PHYSFS
diff --git a/src/fs/virtfs/virtfs.cpp b/src/fs/virtfs/virtfs.cpp
index 9cc36fda8..dd305303a 100644
--- a/src/fs/virtfs/virtfs.cpp
+++ b/src/fs/virtfs/virtfs.cpp
@@ -36,7 +36,6 @@
#include "fs/virtfs/zip.h"
#include "utils/checkutils.h"
-#include "utils/dtor.h"
#include "utils/stringutils.h"
#include "debug.h"
@@ -107,7 +106,7 @@ namespace VirtFs
{
FOR_EACH (std::vector<VirtFsEntry*>::const_iterator, it, mEntries)
{
- VirtFsEntry *const entry = *it;
+ const VirtFsEntry *const entry = *it;
if (entry->root == root &&
entry->type == type)
{
@@ -282,7 +281,7 @@ namespace VirtFs
std::string rootDir = newDir;
if (findLast(rootDir, std::string(dirSeparator)) == false)
rootDir += dirSeparator;
- VirtFsEntry *const entry = searchEntryByRootInternal(rootDir);
+ const VirtFsEntry *const entry = searchEntryByRootInternal(rootDir);
if (entry != nullptr)
{
reportAlways("VirtFs::addToSearchPath already exists: %s",
@@ -506,7 +505,6 @@ namespace VirtFs
else
delete entry;
}
-// delete_all(mEntries);
mEntries.clear();
return true;
}
diff --git a/src/fs/virtfs/virtfs_unittest.cc b/src/fs/virtfs/virtfs_unittest.cc
index bf040d707..66a9c6435 100644
--- a/src/fs/virtfs/virtfs_unittest.cc
+++ b/src/fs/virtfs/virtfs_unittest.cc
@@ -192,7 +192,6 @@ TEST_CASE("VirtFs1 mountZip")
std::string name("data/test/test.zip");
std::string prefix;
const std::string sep = dirSeparator;
- std::vector<ZipLocalHeader*> headers;
if (Files::existsLocal(name) == false)
prefix = "../";
@@ -311,7 +310,6 @@ TEST_CASE("VirtFs1 removeFromSearchPath")
std::string name("data/test/test.zip");
std::string prefix;
const std::string sep = dirSeparator;
- std::vector<ZipLocalHeader*> headers;
if (Files::existsLocal(name) == false)
prefix = "../";
@@ -676,7 +674,7 @@ TEST_CASE("VirtFs1 getRealDir2")
delete2(logger);
}
-static bool inList(VirtList *list,
+static bool inList(const VirtList *const list,
const std::string &name)
{
FOR_EACH (StringVectCIter, it, list->names)
@@ -745,7 +743,6 @@ TEST_CASE("VirtFs1 enumerateFiles2")
VirtList *list = nullptr;
list = VirtFs::enumerateFiles("/");
- const size_t sz = list->names.size();
REQUIRE(list->names.size() == 5);
REQUIRE(inList(list, "file1.txt"));
REQUIRE_FALSE(inList(list, "file2.txt"));
@@ -772,7 +769,6 @@ TEST_CASE("VirtFs1 enumerateFiles3")
list = VirtFs::enumerateFiles("/");
const size_t sz = list->names.size();
- REQUIRE(list->names.size() == 6);
REQUIRE(inList(list, "file1.txt"));
REQUIRE(inList(list, "file2.txt"));
VirtFs::freeList(list);
diff --git a/src/fs/virtfs/virtfsdir.cpp b/src/fs/virtfs/virtfsdir.cpp
index ba320ae2e..69e8fd25a 100644
--- a/src/fs/virtfs/virtfsdir.cpp
+++ b/src/fs/virtfs/virtfsdir.cpp
@@ -25,7 +25,6 @@
#include "fs/files.h"
#include "fs/mkdir.h"
#include "fs/paths.h"
-#include "fs/virtfs.h"
#include "fs/virtfile.h"
#include "fs/virtfsfuncs.h"
#include "fs/virtlist.h"
@@ -34,7 +33,6 @@
#include "fs/virtfs/virtfileprivate.h"
#include "utils/checkutils.h"
-#include "utils/dtor.h"
#include "utils/stringutils.h"
#include <dirent.h>
@@ -167,7 +165,6 @@ namespace VirtFsDir
std::string &realDir)
{
VirtDirEntry *const dirEntry = static_cast<VirtDirEntry*>(entry);
- const std::string path = dirEntry->root + filename;
if (Files::existsLocal(dirEntry->root + filename))
{
realDir = dirEntry->userDir;
diff --git a/src/fs/virtfs/virtfsdir.h b/src/fs/virtfs/virtfsdir.h
index e689fcd95..b292bd71d 100644
--- a/src/fs/virtfs/virtfsdir.h
+++ b/src/fs/virtfs/virtfsdir.h
@@ -22,9 +22,6 @@
#define UTILS_VIRTFSDIR_H
#ifndef USE_PHYSFS
-#include "enums/simpletypes/append.h"
-#include "enums/simpletypes/skiperror.h"
-
#include "fs/virtfs/fileapi.h"
#include "utils/stringvector.h"
diff --git a/src/fs/virtfs/virtfszip.cpp b/src/fs/virtfs/virtfszip.cpp
index 0f1021793..e085ac307 100644
--- a/src/fs/virtfs/virtfszip.cpp
+++ b/src/fs/virtfs/virtfszip.cpp
@@ -22,8 +22,6 @@
#include "fs/virtfs/virtfszip.h"
-#include "fs/files.h"
-#include "fs/paths.h"
#include "fs/virtfsfuncs.h"
#include "fs/virtfile.h"
#include "fs/virtlist.h"
@@ -34,7 +32,6 @@
#include "fs/virtfs/ziplocalheader.h"
#include "utils/checkutils.h"
-#include "utils/dtor.h"
#include "utils/stringutils.h"
#include "debug.h"
@@ -222,7 +219,7 @@ namespace VirtFsZip
it2,
zipEntry->mHeaders)
{
- ZipLocalHeader *restrict const header = *it2;
+ const ZipLocalHeader *restrict const header = *it2;
if (header->fileName == filename)
{
uint8_t *restrict const buf = Zip::readFile(header);
diff --git a/src/fs/virtfs/virtfszip.h b/src/fs/virtfs/virtfszip.h
index bf4f5b3be..f615e38fd 100644
--- a/src/fs/virtfs/virtfszip.h
+++ b/src/fs/virtfs/virtfszip.h
@@ -22,9 +22,6 @@
#define UTILS_VIRTFSZIP_H
#ifndef USE_PHYSFS
-#include "enums/simpletypes/append.h"
-#include "enums/simpletypes/skiperror.h"
-
#include "utils/stringvector.h"
#include "localconsts.h"
diff --git a/src/fs/virtfs/virtzipentry.cpp b/src/fs/virtfs/virtzipentry.cpp
index 324e54fb4..216603bed 100644
--- a/src/fs/virtfs/virtzipentry.cpp
+++ b/src/fs/virtfs/virtzipentry.cpp
@@ -31,7 +31,8 @@
VirtZipEntry::VirtZipEntry(const std::string &restrict archiveName,
VirtFsFuncs *restrict const funcs0) :
VirtFsEntry(FsEntryType::Zip, funcs0),
- mHeaders()
+ mHeaders(),
+ mDirs()
{
root = archiveName;
}
diff --git a/src/fs/virtfs/zip.cpp b/src/fs/virtfs/zip.cpp
index 5ce90069e..d7bb095c3 100644
--- a/src/fs/virtfs/zip.cpp
+++ b/src/fs/virtfs/zip.cpp
@@ -89,7 +89,6 @@ namespace Zip
archiveName.c_str());
return false;
}
- size_t cnt = 0U;
uint8_t *const buf = new uint8_t[65535 + 10];
uint16_t val16 = 0U;
uint16_t method = 0U;
@@ -102,6 +101,7 @@ namespace Zip
// format source https://en.wikipedia.org/wiki/Zip_%28file_format%29
while (feof(arcFile) == 0)
{
+ size_t cnt = 0U;
// file header pointer on 0
// read file header signature
readVal(buf, 4, "zip file header"); // + 4
diff --git a/src/fs/virtfs/zip.h b/src/fs/virtfs/zip.h
index ddb5d7508..8efbd05e4 100644
--- a/src/fs/virtfs/zip.h
+++ b/src/fs/virtfs/zip.h
@@ -25,7 +25,6 @@
#include "localconsts.h"
#include <string>
-#include <vector>
struct VirtZipEntry;
struct ZipLocalHeader;
diff --git a/src/fs/virtfs/ziplocalheader.cpp b/src/fs/virtfs/ziplocalheader.cpp
index eb8ba3e78..36224aa68 100644
--- a/src/fs/virtfs/ziplocalheader.cpp
+++ b/src/fs/virtfs/ziplocalheader.cpp
@@ -26,8 +26,6 @@
#include "localconsts.h"
-#include <string>
-
#include "debug.h"
ZipLocalHeader::ZipLocalHeader() :
diff --git a/src/fs/virtfs_unittest.cc b/src/fs/virtfs_unittest.cc
index 0ef26ae9f..a5844c032 100644
--- a/src/fs/virtfs_unittest.cc
+++ b/src/fs/virtfs_unittest.cc
@@ -216,7 +216,7 @@ static void removeTemp(StringVect &restrict list)
}
}
-static bool inList(VirtList *list,
+static bool inList(const VirtList *const list,
const std::string &name)
{
FOR_EACH (StringVectCIter, it, list->names)
@@ -280,7 +280,6 @@ TEST_CASE("VirtFs enumerateFiles2")
VirtList *list = nullptr;
list = VirtFs::enumerateFiles("/");
- const size_t sz = list->names.size();
REQUIRE(list->names.size() == 5);
VirtFs::freeList(list);
diff --git a/src/fs/virtfsfuncs.h b/src/fs/virtfsfuncs.h
index b78643f7f..c931a2263 100644
--- a/src/fs/virtfsfuncs.h
+++ b/src/fs/virtfsfuncs.h
@@ -41,6 +41,15 @@ struct VirtFsFuncs final
fileLength(nullptr),
tell(nullptr),
seek(nullptr),
+#ifndef USE_PHYSFS
+ exists(nullptr),
+ getRealDir(nullptr),
+ enumerate(nullptr),
+ isDirectory(nullptr),
+ openRead(nullptr),
+ openWrite(nullptr),
+ openAppend(nullptr),
+#endif
eof(nullptr)
{
}
@@ -60,7 +69,6 @@ struct VirtFsFuncs final
int64_t (*tell) (VirtFile *restrict const file);
int (*seek) (VirtFile *restrict const file,
const uint64_t pos);
- int (*eof) (VirtFile *restrict const file);
#ifndef USE_PHYSFS
bool (*exists) (VirtFsEntry *restrict const entry,
const std::string &filename,
@@ -82,6 +90,7 @@ struct VirtFsFuncs final
VirtFile *(*openAppend) (VirtFsEntry *restrict const entry,
const std::string &filename);
#endif // USE_PHYSFS
+ int (*eof) (VirtFile *restrict const file);
};
#endif // UTILS_VIRTFSFUNCS_H
diff --git a/src/fs/virtfstools.cpp b/src/fs/virtfstools.cpp
index 9ba8c6683..074044908 100644
--- a/src/fs/virtfstools.cpp
+++ b/src/fs/virtfstools.cpp
@@ -25,11 +25,6 @@
#include "fs/paths.h"
#include "fs/virtfs.h"
-#ifdef USE_PHYSFS
-#include "fs/physfs/virtfsphys.h"
-#else // USE_PHYSFS
-#include "fs/virtfs/virtfsdir.h"
-#endif // USE_PHYSFS
#include "fs/virtlist.h"
#include "utils/stringutils.h"
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index a491e191a..df9b9ae9b 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -292,7 +292,7 @@ void Viewport::followMouse()
if (mPlayerFollowMouse && (button & SDL_BUTTON(1)))
{
// We create a mouse event and send it to mouseDragged.
- MouseEvent event(nullptr,
+ const MouseEvent event(nullptr,
MouseEventType::DRAGGED,
MouseButton::LEFT,
mMouseX,
diff --git a/src/integrity_unittest.cc b/src/integrity_unittest.cc
index a585570cd..fd01ce171 100644
--- a/src/integrity_unittest.cc
+++ b/src/integrity_unittest.cc
@@ -262,7 +262,7 @@ TEST_CASE("integrity tests", "integrity")
SDL_RWclose(rw);
VirtFs::unmountZip(prefix + "data/test/test.zip");
VirtFs::mountDirSilent(prefix + "data/test", Append_true);
- REQUIRE(compareBuffers(buf) == true);
+ REQUIRE(compareBuffers(buf));
VirtFs::unmountDirSilent(prefix + "data/test");
}
@@ -409,7 +409,7 @@ TEST_CASE("integrity tests", "integrity")
VirtFs::unmountZip("../data/test/test.zip");
VirtFs::mountDirSilent("data/test", Append_true);
VirtFs::mountDirSilent("../data/test", Append_true);
- REQUIRE(compareBuffers(buf) == true);
+ REQUIRE(compareBuffers(buf));
VirtFs::unmountDirSilent("data/test");
VirtFs::unmountDirSilent("../data/test");
}
@@ -447,7 +447,7 @@ TEST_CASE("integrity tests", "integrity")
VirtFs::unmountZip(prefix + "data/test/test.zip");
VirtFs::mountDirSilent("data/test", Append_true);
VirtFs::mountDirSilent("../data/test", Append_true);
- REQUIRE(compareBuffers(buf) == true);
+ REQUIRE(compareBuffers(buf));
VirtFs::unmountDirSilent("data/test");
VirtFs::unmountDirSilent("../data/test");
}
diff --git a/src/maingui.cpp b/src/maingui.cpp
index f4e80ac97..b4e675231 100644
--- a/src/maingui.cpp
+++ b/src/maingui.cpp
@@ -35,7 +35,6 @@
#include "fs/paths.h"
#endif // ANDROID
#include "utils/process.h"
-#include "utils/xml.h"
#ifdef __MINGW32__
#include <windows.h>
@@ -53,6 +52,8 @@
#ifdef UNITTESTS
#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
+#else // UNITTESTS
+#include "utils/xml.h"
#endif // UNITTESTS
#define SDL_IMAGE_COMPILEDVERSION \
diff --git a/src/resources/resourcemanager/resourcemanager_unittest.cc b/src/resources/resourcemanager/resourcemanager_unittest.cc
index d85202f32..dce156bfb 100644
--- a/src/resources/resourcemanager/resourcemanager_unittest.cc
+++ b/src/resources/resourcemanager/resourcemanager_unittest.cc
@@ -76,7 +76,6 @@ namespace
const TestLoader *const rl
= static_cast<const TestLoader *const>(v);
- std::string path1 = rl->path;
Resource *const res = new TestResource();
BLOCK_END("TestLoader::load")
return res;