From 7676e9b4c8b4060d44cc9e9115d0a6340bbc9c50 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 18 Feb 2023 15:33:28 -0330 Subject: [PATCH] Some fixes for warnings from cppcheck. --- src/common/SoundNull.hxx | 15 ++++++++------- src/common/ZipHandler.cxx | 22 +++++++++++----------- src/common/main.cxx | 4 ++-- src/debugger/TimerMap.hxx | 22 ++++++++++------------ src/emucore/CartMVC.cxx | 34 ++++++++-------------------------- src/emucore/KidVid.cxx | 4 ++-- 6 files changed, 41 insertions(+), 60 deletions(-) diff --git a/src/common/SoundNull.hxx b/src/common/SoundNull.hxx index 30849b7c4..3dfeae220 100644 --- a/src/common/SoundNull.hxx +++ b/src/common/SoundNull.hxx @@ -101,18 +101,19 @@ class SoundNull : public Sound */ void adjustVolume(int direction = 1) override { } - /** - Sets the audio device. - - @param device The number of the device to select (0 = default). - */ - void setDevice(uInt32 device) override { } - /** This method is called to provide information about the sound device. */ string about() const override { return "Sound disabled"; } + protected: + /** + This method is called to query the audio devices. + + @param devices List of device names + */ + void queryHardware(VariantList& devices) override { } + private: // Following constructors and assignment operators not supported SoundNull() = delete; diff --git a/src/common/ZipHandler.cxx b/src/common/ZipHandler.cxx index 5e709d74c..15a08d8fb 100644 --- a/src/common/ZipHandler.cxx +++ b/src/common/ZipHandler.cxx @@ -44,9 +44,8 @@ void ZipHandler::open(const string& filename) else { // Allocate memory for the ZipFile structure - ptr = make_unique(filename); - if(ptr == nullptr) - throw runtime_error(errorMessage(ZipError::OUT_OF_MEMORY)); + try { ptr = make_unique(filename); } + catch(...) { throw runtime_error(errorMessage(ZipError::OUT_OF_MEMORY)); } // Open the file and initialize it if(!ptr->open()) @@ -109,13 +108,11 @@ uInt64 ZipHandler::decompress(ByteBuffer& image) { if(myZip && myZip->myHeader.uncompressedLength > 0) { - const uInt64 length = myZip->myHeader.uncompressedLength; - image = make_unique(length); - if(image == nullptr) - throw runtime_error(errorMessage(ZipError::OUT_OF_MEMORY)); - try { + const uInt64 length = myZip->myHeader.uncompressedLength; + image = make_unique(length); + myZip->decompress(image, length); return length; } @@ -123,6 +120,10 @@ uInt64 ZipHandler::decompress(ByteBuffer& image) { throw runtime_error(errorMessage(err)); } + catch(...) + { + throw runtime_error(errorMessage(ZipError::OUT_OF_MEMORY)); + } } else throw runtime_error("Invalid ZIP archive"); @@ -235,9 +236,8 @@ void ZipHandler::ZipFile::initialize() throw runtime_error(errorMessage(ZipError::UNSUPPORTED)); // Allocate memory for the central directory - myCd = make_unique(myEcd.cdSize + 1); - if(myCd == nullptr) - throw runtime_error(errorMessage(ZipError::OUT_OF_MEMORY)); + try { myCd = make_unique(myEcd.cdSize + 1); } + catch(...) { throw runtime_error(errorMessage(ZipError::OUT_OF_MEMORY)); } // Read the central directory uInt64 read_length = 0; diff --git a/src/common/main.cxx b/src/common/main.cxx index dbdb7affa..78bf0d027 100644 --- a/src/common/main.cxx +++ b/src/common/main.cxx @@ -51,7 +51,7 @@ Some keys are used only by the main function; these are placed in localOpts. The rest are needed globally, and are placed in globalOpts. */ -void parseCommandLine(int ac, char* av[], +void parseCommandLine(int ac, const char* const av[], Settings::Options& globalOpts, Settings::Options& localOpts); /** @@ -84,7 +84,7 @@ void freeConsole(); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void parseCommandLine(int ac, char* av[], +void parseCommandLine(int ac, const char* const av[], Settings::Options& globalOpts, Settings::Options& localOpts) { localOpts["ROMFILE"] = ""; // make sure we have an entry for this diff --git a/src/debugger/TimerMap.hxx b/src/debugger/TimerMap.hxx index 815bec08f..d0209efdb 100644 --- a/src/debugger/TimerMap.hxx +++ b/src/debugger/TimerMap.hxx @@ -62,9 +62,9 @@ class TimerMap { TimerPoint from{}; TimerPoint to{}; - bool mirrors{false}; - bool anyBank{false}; - bool isPartial{false}; + bool mirrors{false}; + bool anyBank{false}; + bool isPartial{false}; uInt64 execs{0}; uInt64 lastCycles{0}; @@ -84,20 +84,18 @@ class TimerMap c_mirrors, c_anyBank); } - Timer(const TimerPoint& tp, bool c_mirrors = false, bool c_anyBank = false) - { - from = tp; - mirrors = c_mirrors; - anyBank = c_anyBank; - isPartial = true; - } + explicit Timer(const TimerPoint& tp, bool c_mirrors = false, + bool c_anyBank = false) + : from{tp}, mirrors{c_mirrors}, anyBank{c_anyBank}, isPartial{true} {} - Timer(uInt16 addr, uInt8 bank, bool c_mirrors = false, bool c_anyBank = false) + Timer(uInt16 addr, uInt8 bank, bool c_mirrors = false, + bool c_anyBank = false) { Timer(TimerPoint(addr, bank), c_mirrors, c_anyBank); } - void setTo(const TimerPoint& tp, bool c_mirrors = false, bool c_anyBank = false) + void setTo(const TimerPoint& tp, bool c_mirrors = false, + bool c_anyBank = false) { to = tp; mirrors |= c_mirrors; diff --git a/src/emucore/CartMVC.cxx b/src/emucore/CartMVC.cxx index d775c208d..5348c55ab 100755 --- a/src/emucore/CartMVC.cxx +++ b/src/emucore/CartMVC.cxx @@ -1481,9 +1481,9 @@ bool MovieCart::save(Serializer& out) const out.putByte(myDrawLevelBars); out.putByte(myDrawTimeCode); - if(!myStream.save(out)) throw; - if(!myInputs.save(out)) throw; - if(!myLastInputs.save(out)) throw; + if(!myStream.save(out)) return false; + if(!myInputs.save(out)) return false; + if(!myLastInputs.save(out)) return false; out.putByte(mySpeed); out.putByte(myJoyRepeat); @@ -1535,9 +1535,9 @@ bool MovieCart::load(Serializer& in) myDrawLevelBars = in.getByte(); myDrawTimeCode = in.getByte(); - if(!myStream.load(in)) throw; - if(!myInputs.load(in)) throw; - if(!myLastInputs.load(in)) throw; + if(!myStream.load(in)) return false; + if(!myInputs.load(in)) return false; + if(!myLastInputs.load(in)) return false; mySpeed = in.getByte(); myJoyRepeat = in.getByte(); @@ -1621,29 +1621,11 @@ bool CartridgeMVC::poke(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeMVC::save(Serializer& out) const { - try - { - if(!myMovie->save(out)) throw; - } - catch(...) - { - return false; - } - - return true; + return myMovie->save(out); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeMVC::load(Serializer& in) { - try - { - if(!myMovie->load(in)) throw; - } - catch(...) - { - return false; - } - - return true; + return myMovie->load(in); } diff --git a/src/emucore/KidVid.cxx b/src/emucore/KidVid.cxx index d25c9d989..4a517f581 100644 --- a/src/emucore/KidVid.cxx +++ b/src/emucore/KidVid.cxx @@ -255,6 +255,7 @@ const char* KidVid::getFileName() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void KidVid::openSampleFiles() { +#ifdef SOUND_SUPPORT static constexpr uInt32 firstSongPointer[6] = { 44 + 38, 0, @@ -264,7 +265,6 @@ void KidVid::openSampleFiles() 44 + 38 + 42 + 62 }; -#ifdef SOUND_SUPPORT if(!myFilesFound) { int i = myGame == Game::Smurfs ? myTape - 1 : myTape + 2; @@ -280,11 +280,11 @@ void KidVid::openSampleFiles() << "found file: " << "KVSHARED.WAV" << endl; #endif -#endif mySongLength = 0; mySongPointer = firstSongPointer[i]; } myTapeBusy = false; +#endif } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -