From 72eb9ec9eab5efcb3aa99a962a80423e8c0a3232 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sun, 3 Jan 2010 19:37:43 +0000 Subject: Fixed a bunch of cppcheck warnings. Mostly about checking if a pointer is null before freeing it, which isn't necessary. svn-id: r46941 --- engines/m4/actor.cpp | 3 +-- engines/m4/events.cpp | 3 +-- engines/m4/globals.cpp | 2 +- engines/m4/gui.cpp | 3 +-- engines/m4/m4_menus.cpp | 6 ++---- engines/m4/mads_anim.cpp | 9 +++------ engines/m4/mads_menus.cpp | 6 ++---- engines/m4/midi.cpp | 4 +--- engines/m4/scene.cpp | 19 +++++-------------- engines/m4/script.cpp | 10 +++------- engines/m4/woodscript.cpp | 2 +- 11 files changed, 21 insertions(+), 46 deletions(-) (limited to 'engines/m4') diff --git a/engines/m4/actor.cpp b/engines/m4/actor.cpp index bfb4a14615..82f7361cca 100644 --- a/engines/m4/actor.cpp +++ b/engines/m4/actor.cpp @@ -95,8 +95,7 @@ void Actor::unloadWalkers() { continue; // walker sprite 6 is unused SpriteAsset *tempSprite = _walkerSprites[i]; _walkerSprites.remove_at(i); - if (tempSprite) - delete tempSprite; + delete tempSprite; } } diff --git a/engines/m4/events.cpp b/engines/m4/events.cpp index 751fe8a353..099aa6b48d 100644 --- a/engines/m4/events.cpp +++ b/engines/m4/events.cpp @@ -186,8 +186,7 @@ Mouse::Mouse(M4Engine *vm) : _vm(vm) { } Mouse::~Mouse() { - if (_cursorSprites) - delete _cursorSprites; + delete _cursorSprites; } bool Mouse::init(const char *seriesName, RGB8 *palette) { diff --git a/engines/m4/globals.cpp b/engines/m4/globals.cpp index b21c17edd8..6461025165 100644 --- a/engines/m4/globals.cpp +++ b/engines/m4/globals.cpp @@ -397,7 +397,7 @@ const char *Globals::loadMessage(uint index) { if (buffer[i] == '\0') buffer[i] = '\n'; _vm->res()->toss("messages.dat"); - delete compData; + delete[] compData; return (char*)buffer; } diff --git a/engines/m4/gui.cpp b/engines/m4/gui.cpp index e11a654e64..dc75b94fd7 100644 --- a/engines/m4/gui.cpp +++ b/engines/m4/gui.cpp @@ -90,8 +90,7 @@ MenuObject::MenuObject(DialogView *owner, int objectId, int xs, int ys, int widt } MenuObject::~MenuObject() { - if (_background) - delete _background; + delete _background; } void MenuObject::onExecute() { diff --git a/engines/m4/m4_menus.cpp b/engines/m4/m4_menus.cpp index 220f58aac9..827d1ac3f8 100644 --- a/engines/m4/m4_menus.cpp +++ b/engines/m4/m4_menus.cpp @@ -433,10 +433,8 @@ OrionMenuView::~OrionMenuView() { delete *i; _menuObjects.clear(); - if (_saveNames) - delete _saveNames; - if (_savegameThumbnail) - delete _savegameThumbnail; + delete _saveNames; + delete _savegameThumbnail; } bool OrionMenuView::loadSprites(const char *seriesName) { diff --git a/engines/m4/mads_anim.cpp b/engines/m4/mads_anim.cpp index c8e0ddd89d..76f6fd712d 100644 --- a/engines/m4/mads_anim.cpp +++ b/engines/m4/mads_anim.cpp @@ -75,12 +75,9 @@ TextviewView::TextviewView(M4Engine *vm): TextviewView::~TextviewView() { if (_script) _vm->res()->toss(_resourceName); - if (_spareScreen) - delete _spareScreen; - if (_bgCurrent) - delete _bgCurrent; - if (_bgSpare) - delete _bgSpare; + delete _spareScreen; + delete _bgCurrent; + delete _bgSpare; } void TextviewView::reset() { diff --git a/engines/m4/mads_menus.cpp b/engines/m4/mads_menus.cpp index 2f5a0107bd..196f7ff7b0 100644 --- a/engines/m4/mads_menus.cpp +++ b/engines/m4/mads_menus.cpp @@ -74,8 +74,7 @@ RexMainMenuView::RexMainMenuView(M4Engine *vm): } RexMainMenuView::~RexMainMenuView() { - if (_menuItem) - delete _menuItem; + delete _menuItem; _vm->_palette->deleteRange(_bgPalData); @@ -121,8 +120,7 @@ bool RexMainMenuView::onEvent(M4EventType eventType, int32 param, int x, int y, // Goodness knows why, but Rex has a key to restart the menuitem animations // Delete the current menu items - if (_menuItem) - delete _menuItem; + delete _menuItem; _vm->_palette->deleteRange(_bgPalData); delete _bgPalData; diff --git a/engines/m4/midi.cpp b/engines/m4/midi.cpp index 201d7d3f5f..2696bf566a 100644 --- a/engines/m4/midi.cpp +++ b/engines/m4/midi.cpp @@ -47,9 +47,7 @@ MidiPlayer::~MidiPlayer() { stopMusic(); close(); delete _parser; - - if (_midiData) - free(_midiData); + free(_midiData); } void MidiPlayer::setVolume(int volume) { diff --git a/engines/m4/scene.cpp b/engines/m4/scene.cpp index 905cb744c3..f61a2e88ce 100644 --- a/engines/m4/scene.cpp +++ b/engines/m4/scene.cpp @@ -73,21 +73,13 @@ Scene::~Scene() { delete _backgroundSurface; delete _codeSurface; - - if (_sceneSprites) - delete _sceneSprites; + delete _sceneSprites; // _vm->_palette->deleteAllRanges(); - if (_palData) - delete _palData; - - if (_interfacePal) - delete _interfacePal; - - if (_inverseColorTable) - delete[] _inverseColorTable; - + delete _palData; + delete _interfacePal; + delete[] _inverseColorTable; } void Scene::loadScene(int sceneNumber) { @@ -284,8 +276,7 @@ void Scene::loadSceneInverseColorTable(int sceneNumber) { if (_vm->isM4()) { sprintf(filename, "%i.ipl", sceneNumber); iplS = _vm->res()->openFile(filename); - if (_inverseColorTable) - delete[] _inverseColorTable; + delete[] _inverseColorTable; _inverseColorTable = new byte[iplS->size()]; iplS->read(_inverseColorTable, iplS->size()); _vm->res()->toss(filename); diff --git a/engines/m4/script.cpp b/engines/m4/script.cpp index c74d533093..6a2841053c 100644 --- a/engines/m4/script.cpp +++ b/engines/m4/script.cpp @@ -101,8 +101,7 @@ StringTable::StringTable() : _stringsData(NULL) { } StringTable::~StringTable() { - if (_stringsData) - delete[] _stringsData; + delete[] _stringsData; } void StringTable::load(Common::File *fd) { @@ -191,8 +190,7 @@ ScriptFunction::ScriptFunction(ScriptInterpreter *inter) : _inter(inter) { } ScriptFunction::~ScriptFunction() { - if (_code) - delete _code; + delete _code; } void ScriptFunction::load(Common::File *fd) { @@ -293,9 +291,7 @@ void ScriptInterpreter::open(const char *filename) { } void ScriptInterpreter::close() { - if (_scriptFile) { - delete _scriptFile; - } + delete _scriptFile; } void ScriptInterpreter::initScriptKernel() { diff --git a/engines/m4/woodscript.cpp b/engines/m4/woodscript.cpp index 25cfaa7664..036f5d101f 100644 --- a/engines/m4/woodscript.cpp +++ b/engines/m4/woodscript.cpp @@ -180,7 +180,7 @@ Sequence *WoodScript::createSequence(Machine *machine, int32 sequenceHash) { void WoodScript::runSequencePrograms() { // A lot TODO - for (Common::Array::iterator it = _sequences.begin(); it != _sequences.end(); it++) { + for (Common::Array::iterator it = _sequences.begin(); it != _sequences.end(); ++it) { Sequence *sequence = *it; if (sequence->isActive()) { sequence->runProgram(); -- cgit v1.2.3