Some fixes for warnings from cppcheck.

This commit is contained in:
Stephen Anthony 2023-02-18 15:33:28 -03:30
parent e5af3b20d3
commit 7676e9b4c8
6 changed files with 41 additions and 60 deletions

View File

@ -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;

View File

@ -44,9 +44,8 @@ void ZipHandler::open(const string& filename)
else
{
// Allocate memory for the ZipFile structure
ptr = make_unique<ZipFile>(filename);
if(ptr == nullptr)
throw runtime_error(errorMessage(ZipError::OUT_OF_MEMORY));
try { ptr = make_unique<ZipFile>(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<uInt8[]>(length);
if(image == nullptr)
throw runtime_error(errorMessage(ZipError::OUT_OF_MEMORY));
try
{
const uInt64 length = myZip->myHeader.uncompressedLength;
image = make_unique<uInt8[]>(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<uInt8[]>(myEcd.cdSize + 1);
if(myCd == nullptr)
throw runtime_error(errorMessage(ZipError::OUT_OF_MEMORY));
try { myCd = make_unique<uInt8[]>(myEcd.cdSize + 1); }
catch(...) { throw runtime_error(errorMessage(ZipError::OUT_OF_MEMORY)); }
// Read the central directory
uInt64 read_length = 0;

View File

@ -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

View File

@ -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;

View File

@ -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);
}

View File

@ -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
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -