From 916a2cdfff0a79ef39942bf12fce4974f6bc51ac Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Tue, 5 Jan 2021 22:36:16 -0330 Subject: [PATCH] Fixes for suggestions from cppcheck. --- src/common/HighScoresManager.cxx | 2 +- src/common/HighScoresManager.hxx | 28 +++++++++---------- .../repository/CompositeKVRJsonAdapter.cxx | 4 +-- .../repository/CompositeKVRJsonAdapter.hxx | 2 +- .../CompositeKeyValueRepositoryNoop.hxx | 8 ++++-- .../KeyValueRepositoryConfigfile.hxx | 2 +- .../repository/KeyValueRepositoryFile.hxx | 2 +- src/gui/HighScoresMenu.cxx | 2 +- 8 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/common/HighScoresManager.cxx b/src/common/HighScoresManager.cxx index 8d47cc329..d471808cc 100644 --- a/src/common/HighScoresManager.cxx +++ b/src/common/HighScoresManager.cxx @@ -565,7 +565,7 @@ Int32 HighScoresManager::fromBCD(uInt8 bcd) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string HighScoresManager::hash(ScoresData& data) const +string HighScoresManager::hash(const ScoresData& data) const { ostringstream buf; diff --git a/src/common/HighScoresManager.hxx b/src/common/HighScoresManager.hxx index 9528d3385..3dfd0da54 100644 --- a/src/common/HighScoresManager.hxx +++ b/src/common/HighScoresManager.hxx @@ -54,31 +54,31 @@ namespace HSM { struct ScoresProps { // Formats - uInt32 numDigits; - uInt32 trailingZeroes; - bool scoreBCD; - bool scoreInvert; - bool varsBCD; - bool varsZeroBased; + uInt32 numDigits{0}; + uInt32 trailingZeroes{0}; + bool scoreBCD{false}; + bool scoreInvert{false}; + bool varsBCD{false}; + bool varsZeroBased{false}; string special; - bool specialBCD; - bool specialZeroBased; + bool specialBCD{false}; + bool specialZeroBased{false}; string notes; // Addresses ScoreAddresses scoreAddr; - uInt16 varsAddr; - uInt16 specialAddr; + uInt16 varsAddr{0}; + uInt16 specialAddr{0}; }; struct ScoreEntry { - Int32 score; - Int32 special; + Int32 score{0}; + Int32 special{0}; string name; string date; }; struct ScoresData { - Int32 variation; + Int32 variation{0}; string md5; ScoreEntry scores[NUM_RANKS]; }; @@ -232,7 +232,7 @@ class HighScoresManager uInt16 fromHexStr(const string& addr) const; Int32 fromBCD(uInt8 bcd) const; - string hash(HSM::ScoresData& data) const; + string hash(const HSM::ScoresData& data) const; /** Loads the current high scores for this game and variation from the given JSON object. diff --git a/src/common/repository/CompositeKVRJsonAdapter.cxx b/src/common/repository/CompositeKVRJsonAdapter.cxx index 0ef8cd8c0..62d1bd9a5 100644 --- a/src/common/repository/CompositeKVRJsonAdapter.cxx +++ b/src/common/repository/CompositeKVRJsonAdapter.cxx @@ -24,7 +24,7 @@ namespace { class ProxyRepository : public KeyValueRepository { public: ProxyRepository(KeyValueRepositoryAtomic& kvr, const string& key) - : myKvr(kvr), myKey(key) + : myKvr{kvr}, myKey{key} {} std::map load() override { @@ -55,7 +55,7 @@ namespace { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CompositeKVRJsonAdapter::CompositeKVRJsonAdapter(KeyValueRepositoryAtomic& kvr) - : myKvr(kvr) + : myKvr{kvr} {} // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/repository/CompositeKVRJsonAdapter.hxx b/src/common/repository/CompositeKVRJsonAdapter.hxx index 950782207..026fa18cd 100644 --- a/src/common/repository/CompositeKVRJsonAdapter.hxx +++ b/src/common/repository/CompositeKVRJsonAdapter.hxx @@ -25,7 +25,7 @@ class CompositeKVRJsonAdapter : public CompositeKeyValueRepository { public: - CompositeKVRJsonAdapter(KeyValueRepositoryAtomic& kvr); + explicit CompositeKVRJsonAdapter(KeyValueRepositoryAtomic& kvr); shared_ptr get(const string& key) override; diff --git a/src/common/repository/CompositeKeyValueRepositoryNoop.hxx b/src/common/repository/CompositeKeyValueRepositoryNoop.hxx index a2457ee69..2c658b00f 100644 --- a/src/common/repository/CompositeKeyValueRepositoryNoop.hxx +++ b/src/common/repository/CompositeKeyValueRepositoryNoop.hxx @@ -29,11 +29,13 @@ class CompositeKeyValueRepositoryNoop : public CompositeKeyValueRepositoryAtomic using CompositeKeyValueRepositoryAtomic::remove; using CompositeKeyValueRepositoryAtomic::get; - shared_ptr get(const string& key) { return make_shared(); } + shared_ptr get(const string& key) override { + return make_shared(); + } - bool has(const string& key) { return false; } + bool has(const string& key) override { return false; } - void remove(const string& key) {} + void remove(const string& key) override {} }; #endif // COMPOSITE_KEY_VALUE_REPOSITORY_NOOP_HXX diff --git a/src/common/repository/KeyValueRepositoryConfigfile.hxx b/src/common/repository/KeyValueRepositoryConfigfile.hxx index 3b613d816..595bc8a19 100644 --- a/src/common/repository/KeyValueRepositoryConfigfile.hxx +++ b/src/common/repository/KeyValueRepositoryConfigfile.hxx @@ -27,7 +27,7 @@ class KeyValueRepositoryConfigfile : public KeyValueRepositoryFile::load; using KeyValueRepositoryFile::save; - KeyValueRepositoryConfigfile(const FilesystemNode& node); + explicit KeyValueRepositoryConfigfile(const FilesystemNode& node); static std::map load(istream& in); diff --git a/src/common/repository/KeyValueRepositoryFile.hxx b/src/common/repository/KeyValueRepositoryFile.hxx index 23bccb891..333eff03a 100644 --- a/src/common/repository/KeyValueRepositoryFile.hxx +++ b/src/common/repository/KeyValueRepositoryFile.hxx @@ -46,7 +46,7 @@ class KeyValueRepositoryFile : public KeyValueRepository { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template KeyValueRepositoryFile::KeyValueRepositoryFile(const FilesystemNode& node) - : myNode(node) + : myNode{node} {} // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/HighScoresMenu.cxx b/src/gui/HighScoresMenu.cxx index 93c388436..fade474e4 100644 --- a/src/gui/HighScoresMenu.cxx +++ b/src/gui/HighScoresMenu.cxx @@ -22,7 +22,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HighScoresMenu::HighScoresMenu(OSystem& osystem) - : DialogContainer(osystem) + : DialogContainer{osystem} { }