Some fixes for issues found in cppcheck.

This commit is contained in:
Stephen Anthony 2019-12-15 11:23:14 -03:30
parent cbb8ba4494
commit 56a6ef1a60
13 changed files with 38 additions and 35 deletions

View File

@ -17,11 +17,6 @@
#include "JoyMap.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
JoyMap::JoyMap(void)
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void JoyMap::add(const Event::Type event, const JoyMapping& mapping)
{

View File

@ -30,7 +30,6 @@
class JoyMap
{
public:
struct JoyMapping
{
EventMode mode;
@ -44,10 +43,6 @@ class JoyMap
: mode(EventMode(0)), button(0),
axis(JoyAxis(0)), adir(JoyDir(0)),
hat(0), hdir(JoyHatDir(0)) { }
JoyMapping(const JoyMapping& m)
: mode(m.mode), button(m.button),
axis(m.axis), adir(m.adir),
hat(m.hat), hdir(m.hdir) { }
explicit JoyMapping(EventMode c_mode, int c_button,
JoyAxis c_axis, JoyDir c_adir,
int c_hat, JoyHatDir c_hdir)
@ -65,6 +60,11 @@ class JoyMap
axis(JoyAxis::NONE), adir(JoyDir::NONE),
hat(c_hat), hdir(c_hdir) { }
JoyMapping(const JoyMapping&) = default;
JoyMapping& operator=(const JoyMapping&) = default;
JoyMapping(JoyMapping&&) = default;
JoyMapping& operator=(JoyMapping&&) = default;
bool operator==(const JoyMapping& other) const
{
return (mode == other.mode
@ -78,8 +78,7 @@ class JoyMap
};
using JoyMappingArray = std::vector<JoyMapping>;
JoyMap();
virtual ~JoyMap() = default;
JoyMap() = default;
/** Add new mapping for given event */
void add(const Event::Type event, const JoyMapping& mapping);
@ -142,6 +141,12 @@ class JoyMap
};
std::unordered_map<JoyMapping, Event::Type, JoyHash> myMap;
// Following constructors and assignment operators not supported
JoyMap(const JoyMap&) = delete;
JoyMap(JoyMap&&) = delete;
JoyMap& operator=(const JoyMap&) = delete;
JoyMap& operator=(JoyMap&&) = delete;
};
#endif

View File

@ -14,13 +14,8 @@
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#include "KeyMap.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KeyMap::KeyMap(void)
: myModEnabled(true)
{
}
#include "KeyMap.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void KeyMap::add(const Event::Type event, const Mapping& mapping)

View File

@ -30,7 +30,6 @@
class KeyMap
{
public:
struct Mapping
{
EventMode mode;
@ -38,11 +37,14 @@ class KeyMap
StellaMod mod;
Mapping() : mode(EventMode(0)), key(StellaKey(0)), mod(StellaMod(0)) { }
Mapping(const Mapping& m) : mode(m.mode), key(m.key), mod(m.mod) { }
explicit Mapping(EventMode c_mode, StellaKey c_key, StellaMod c_mod)
: mode(c_mode), key(c_key), mod(c_mod) { }
explicit Mapping(EventMode c_mode, int c_key, int c_mod)
: mode(c_mode), key(StellaKey(c_key)), mod(StellaMod(c_mod)) { }
Mapping(const Mapping&) = default;
Mapping& operator=(const Mapping&) = default;
Mapping(Mapping&&) = default;
Mapping& operator=(Mapping&&) = default;
bool operator==(const Mapping& other) const
{
@ -57,8 +59,7 @@ class KeyMap
};
using MappingArray = std::vector<Mapping>;
KeyMap();
virtual ~KeyMap() = default;
KeyMap() : myModEnabled(true) { }
/** Add new mapping for given event */
void add(const Event::Type event, const Mapping& mapping);
@ -122,6 +123,12 @@ class KeyMap
// pressing it with a movement key could inadvertantly activate
// a Ctrl combo when it isn't wanted)
bool myModEnabled;
// Following constructors and assignment operators not supported
KeyMap(const KeyMap&) = delete;
KeyMap(KeyMap&&) = delete;
KeyMap& operator=(const KeyMap&) = delete;
KeyMap& operator=(KeyMap&&) = delete;
};
#endif

View File

@ -112,7 +112,7 @@ struct Rect
public:
Rect() : top(0), left(0), bottom(0), right(0) { assert(valid()); }
Rect(const Rect& s) : top(s.top), left(s.left), bottom(s.bottom), right(s.right) { assert(valid()); }
Rect(const Size& s) : top(0), left(0), bottom(s.h), right(s.w) { assert(valid()); }
explicit Rect(const Size& s) : top(0), left(0), bottom(s.h), right(s.w) { assert(valid()); }
Rect& operator=(const Rect&) = default;
Rect(uInt32 w, uInt32 h) : top(0), left(0), bottom(h), right(w) { assert(valid()); }
Rect(const Point& p, uInt32 w, uInt32 h) : top(p.y), left(p.x), bottom(h), right(w) { assert(valid()); }

View File

@ -255,7 +255,7 @@ string RewindManager::saveAllStates()
out.putInt(myStateSize);
unique_ptr<uInt8[]> buffer = make_unique<uInt8[]>(myStateSize);
for (uInt32 i = 0; i < numStates; i++)
for (uInt32 i = 0; i < numStates; ++i)
{
RewindState& state = myStateList.current();
Serializer& s = state.data;
@ -310,7 +310,7 @@ string RewindManager::loadAllStates()
myStateSize = in.getInt();
unique_ptr<uInt8[]> buffer = make_unique<uInt8[]>(myStateSize);
for (uInt32 i = 0; i < numStates; i++)
for (uInt32 i = 0; i < numStates; ++i)
{
if (myStateList.full())
compressStates();

View File

@ -308,7 +308,8 @@ void SoundSDL2::processFragment(float* stream, uInt32 length)
{
myResampler->fillFragment(stream, length);
for (uInt32 i = 0; i < length; i++) stream[i] = stream[i] * myVolumeFactor;
for (uInt32 i = 0; i < length; ++i)
stream[i] *= myVolumeFactor;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -24,7 +24,7 @@ class KeyValueRepositoryConfigfile : public KeyValueRepository
{
public:
KeyValueRepositoryConfigfile(const string& filename);
explicit KeyValueRepositoryConfigfile(const string& filename);
std::map<string, Variant> load() override;

View File

@ -42,7 +42,7 @@ std::map<string, Variant> KeyValueRepositorySqlite::load()
myStmtSelect->reset();
}
catch (SqliteError err) {
catch (const SqliteError& err) {
Logger::info(err.message);
}
@ -68,7 +68,7 @@ void KeyValueRepositorySqlite::save(const std::map<string, Variant>& values)
tx.commit();
}
catch (SqliteError err) {
catch (const SqliteError& err) {
Logger::info(err.message);
}
}
@ -86,7 +86,7 @@ void KeyValueRepositorySqlite::save(const string& key, const Variant& value)
myStmtInsert->reset();
}
catch (SqliteError err) {
catch (const SqliteError& err) {
Logger::info(err.message);
}
}

View File

@ -37,7 +37,7 @@ bool SettingsDb::initialize()
mySettingsRepository = make_unique<KeyValueRepositorySqlite>(*myDb, "settings");
mySettingsRepository->initialize();
}
catch (SqliteError err) {
catch (const SqliteError& err) {
Logger::info("sqlite DB " + myDb->fileName() + " failed to initialize: " + err.message);
myDb.reset();

View File

@ -22,9 +22,9 @@
#include "bspf.hxx"
struct SqliteError {
SqliteError(const string _message) : message(_message) {}
explicit SqliteError(const string& _message) : message(_message) {}
SqliteError(sqlite3* handle) : message(sqlite3_errmsg(handle)) {}
explicit SqliteError(sqlite3* handle) : message(sqlite3_errmsg(handle)) {}
const string message;
};

View File

@ -23,7 +23,7 @@ class SqliteDatabase;
class SqliteTransaction {
public:
SqliteTransaction(SqliteDatabase& db);
explicit SqliteTransaction(SqliteDatabase& db);
~SqliteTransaction();

View File

@ -26,7 +26,7 @@ class HqBlitter : public Blitter {
public:
HqBlitter(FrameBufferSDL2& fb);
explicit HqBlitter(FrameBufferSDL2& fb);
static bool isSupported(FrameBufferSDL2 &fb);