From 2d97a4b9d7c6d84cb8b22302cd22f805a4ab76b0 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Mon, 29 Jan 2024 21:53:25 +0100 Subject: Apply readability-delete-null-pointer fixits These checks are unnecessary as deleting a null pointer has no effect. --- src/actorsprite.cpp | 4 +--- src/being.cpp | 15 ++++----------- src/gui/equipmentwindow.cpp | 6 ++---- src/gui/setup_players.cpp | 7 +++---- src/simpleanimation.cpp | 3 +-- 5 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index ab220d45..1db68d31 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -204,9 +204,7 @@ static EffectDescription *getEffectDescription(int effectId) EffectDescription *effectDescription = getEffectDescription(node, &id); - if (default_effect) - delete default_effect; - + delete default_effect; default_effect = effectDescription; } } diff --git a/src/being.cpp b/src/being.cpp index d6b36cc6..ef07684f 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -297,9 +297,7 @@ void Being::setSpeech(const std::string &text, int time) const int speech = config.getIntValue("speech"); if (speech == TEXT_OVERHEAD) { - if (mText) - delete mText; - + delete mText; mText = new Text(mSpeech, getPixelX(), getSpeechTextYPosition(), gcn::Graphics::CENTER, @@ -912,11 +910,8 @@ void Being::drawSpeech(int offsetX, int offsetY) { const bool showName = (speech == NAME_IN_BUBBLE); - if (mText) - { - delete mText; - mText = nullptr; - } + delete mText; + mText = nullptr; mSpeechBubble->setCaption(showName ? mName : "", mTextColor); @@ -943,9 +938,7 @@ void Being::drawSpeech(int offsetX, int offsetY) { mSpeechBubble->setVisible(false); - if (mText) - delete mText; - + delete mText; mText = nullptr; } } diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index d646b78c..4d1d5291 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -83,8 +83,7 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment): void EquipmentWindow::loadEquipBoxes() { - if (mEquipBox) - delete[] mEquipBox; + delete[] mEquipBox; // Load equipment boxes. mBoxesNumber = mEquipment->getSlotNumber(); @@ -110,8 +109,7 @@ void EquipmentWindow::loadEquipBoxes() EquipmentWindow::~EquipmentWindow() { delete mItemPopup; - if (mEquipBox) - delete[] mEquipBox; + delete[] mEquipBox; } void EquipmentWindow::draw(gcn::Graphics *graphics) diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index fe72a29c..529e69a5 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -127,8 +127,8 @@ public: signalBeforeUpdate(); freeWidgets(); - if (mPlayers) - delete mPlayers; + + delete mPlayers; mPlayers = player_relations.getPlayers(); // set up widgets @@ -162,8 +162,7 @@ public: virtual void freeWidgets() { - if (mPlayers) - delete mPlayers; + delete mPlayers; mPlayers = nullptr; delete_all(mWidgets); diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp index 5ab7cf63..72045ca9 100644 --- a/src/simpleanimation.cpp +++ b/src/simpleanimation.cpp @@ -53,8 +53,7 @@ SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode, SimpleAnimation::~SimpleAnimation() { - if (mAnimation) - delete mAnimation; + delete mAnimation; } bool SimpleAnimation::draw(Graphics *graphics, int posX, int posY) const -- cgit v1.2.3-70-g09d2