From 181ecd0c3bf27b47487f973fb83b988fd6ceaecf Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 2 Mar 2013 21:17:13 +0300 Subject: Another fixes after Coverity checks. --- src/gui/charcreatedialog.cpp | 7 ++++++ src/gui/inventorywindow.cpp | 40 +++++++++++++++++------------------ src/gui/itempopup.cpp | 1 + src/gui/outfitwindow.cpp | 5 ++++- src/gui/sdlfont.cpp | 4 ++++ src/gui/statuswindow.cpp | 6 ++---- src/gui/whoisonline.cpp | 15 +++++++------ src/gui/widgets/avatarlistbox.cpp | 3 ++- src/gui/widgets/dropdown.cpp | 6 +----- src/gui/widgets/progressindicator.cpp | 4 +--- src/gui/widgets/scrollarea.cpp | 4 ++-- src/gui/widgets/window.cpp | 5 +++++ 12 files changed, 56 insertions(+), 44 deletions(-) diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 471818302..7ed2f0703 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -139,6 +139,13 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent, mRaceLabel = new Label(this, _("Race:")); mRaceNameLabel = new Label(this, ""); } + else + { + mNextRaceButton = nullptr; + mPrevRaceButton = nullptr; + mRaceLabel = nullptr; + mRaceNameLabel = nullptr; + } // Default to a Male character mMale->setSelected(true); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 9f6fda689..fe51018bf 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -311,7 +311,7 @@ void InventoryWindow::action(const gcn::ActionEvent &event) mItems->setName(mNameFilter->getText()); mItems->updateMatrix(); } - else if (!eventId.find("tag_") && mItems) + else if (!eventId.find("tag_")) { std::string tagName = event.getId().substr(4); mItems->setFilter(ItemDB::getTagId(tagName)); @@ -398,8 +398,7 @@ void InventoryWindow::unselectItem() void InventoryWindow::widgetHidden(const gcn::Event &event) { Window::widgetHidden(event); - if (mItems) - mItems->hidePopup(); + mItems->hidePopup(); } void InventoryWindow::mouseClicked(gcn::MouseEvent &event) @@ -590,16 +589,19 @@ void InventoryWindow::updateButtons(const Item *item) if (mDropButton) mDropButton->setEnabled(true); - if (mUseButton && item && item->isEquipment()) + if (mUseButton) { - if (item->isEquipped()) - mUseButton->setCaption(_("Unequip")); + if (item && item->isEquipment()) + { + if (item->isEquipped()) + mUseButton->setCaption(_("Unequip")); + else + mUseButton->setCaption(_("Equip")); + } else - mUseButton->setCaption(_("Equip")); - } - else - { - mUseButton->setCaption(_("Use")); + { + mUseButton->setCaption(_("Use")); + } } updateDropButton(); @@ -674,8 +676,7 @@ void InventoryWindow::slotsChanged(Inventory *const inventory) } mSlotsBar->setText(strprintf("%d/%d", usedSlots, maxSlots)); - if (mItems) - mItems->updateMatrix(); + mItems->updateMatrix(); } } @@ -690,15 +691,12 @@ void InventoryWindow::updateDropButton() } else { - if (mItems) - { - const Item *const item = mItems->getSelectedItem(); + const Item *const item = mItems->getSelectedItem(); - if (item && item->getQuantity() > 1) - mDropButton->setCaption(_("Drop...")); - else - mDropButton->setCaption(_("Drop")); - } + if (item && item->getQuantity() > 1) + mDropButton->setCaption(_("Drop...")); + else + mDropButton->setCaption(_("Drop")); } } diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index f84a42ce7..8be374bf9 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -49,6 +49,7 @@ ItemPopup::ItemPopup() : mItemDesc(new TextBox(this)), mItemEffect(new TextBox(this)), mItemWeight(new TextBox(this)), + mItemType(ITEM_UNUSABLE), mIcon(new Icon(this, nullptr)), mLastName(""), mLastColor(1) diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index c56df4ef7..f548116f6 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -544,7 +544,10 @@ void OutfitWindow::previous() void OutfitWindow::showCurrentOutfit() { mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1)); - mUnequipCheck->setSelected(mItemsUnequip[mCurrentOutfit]); + if (mCurrentOutfit < static_cast(OUTFITS_COUNT)) + mUnequipCheck->setSelected(mItemsUnequip[mCurrentOutfit]); + else + mUnequipCheck->setSelected(false); mKeyLabel->setCaption(strprintf(_("Key: %s"), keyName(mCurrentOutfit).c_str())); mAwayOutfitCheck->setSelected(mAwayOutfit == mCurrentOutfit); diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index 8b53cafe1..aa512207e 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -74,6 +74,7 @@ class SDLTextChunk final sdlCol.b = static_cast(color.b); sdlCol.r = static_cast(color.r); sdlCol.g = static_cast(color.g); + sdlCol.unused = 0; getSafeUtf8String(text, strBuf); @@ -106,6 +107,7 @@ class SDLTextChunk final sdlCol2.b = static_cast(color2.b); sdlCol2.r = static_cast(color2.r); sdlCol2.g = static_cast(color2.g); + sdlCol2.unused = 0; SDL_Surface *const surface2 = TTF_RenderUTF8_Blended( font, strBuf, sdlCol2); if (!surface2) @@ -260,6 +262,8 @@ void SDLFont::drawString(gcn::Graphics *const graphics, } Graphics *const g = dynamic_cast(graphics); + if (!g) + return; gcn::Color col = g->getColor(); gcn::Color col2 = g->getColor2(); diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 99ee0e655..ddd16fa12 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -177,10 +177,8 @@ StatusWindow::StatusWindow() : if (!max) max = 1; - mHpBar = new ProgressBar(this, max ? - static_cast(PlayerInfo::getAttribute(PlayerInfo::HP)) - / static_cast(max): - static_cast(0), 80, 0, Theme::PROG_HP); + mHpBar = new ProgressBar(this, static_cast(PlayerInfo::getAttribute( + PlayerInfo::HP)) / static_cast(max), 80, 0, Theme::PROG_HP); max = PlayerInfo::getAttribute(PlayerInfo::EXP_NEEDED); mXpBar = new ProgressBar(this, max ? diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index a1058928d..84f0fd2f5 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -713,15 +713,16 @@ void WhoIsOnline::updateSize() const std::string WhoIsOnline::prepareNick(std::string nick, int level, std::string color) const { - const char *const text = encodeLinkText(nick).c_str(); + const std::string text = encodeLinkText(nick); if (mShowLevel && level > 1) { - return strprintf("@@%s|##%s%s (%d)@@", text, - color.c_str(), text, level); + return strprintf("@@%s|##%s%s (%d)@@", text.c_str(), + color.c_str(), text.c_str(), level); } else { - return strprintf("@@%s|##%s%s@@", text, color.c_str(), text); + return strprintf("@@%s|##%s%s@@", text.c_str(), + color.c_str(), text.c_str()); } } @@ -846,7 +847,7 @@ void OnlinePlayer::setText(std::string color) if (mVersion > 0) mText.append(strprintf(" - %d", mVersion)); - const char *const text = encodeLinkText(mNick).c_str(); - mText = strprintf("@@%s|##%s%s %s@@", text, color.c_str(), - text, mText.c_str()); + const std::string text = encodeLinkText(mNick); + mText = strprintf("@@%s|##%s%s %s@@", text.c_str(), color.c_str(), + text.c_str(), mText.c_str()); } diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index b69664ddd..f2907aaf3 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -293,7 +293,8 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) } } - setWidth(parent->getWidth() - 10); + if (parent) + setWidth(parent->getWidth() - 10); BLOCK_END("AvatarListBox::draw") } diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index d4fde01dc..5cffb8d72 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -152,8 +152,7 @@ DropDown::DropDown(const Widget2 *const widget, if (listener) addActionListener(listener); - if (mPopup) - mPopup->adjustSize(); + mPopup->adjustSize(); if (mSkin) { @@ -446,9 +445,6 @@ void DropDown::adjustHeight() void DropDown::dropDown() { - if (!mPopup) - return; - if (!mDroppedDown) { mDroppedDown = true; diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp index 401b45754..c0667f720 100644 --- a/src/gui/widgets/progressindicator.cpp +++ b/src/gui/widgets/progressindicator.cpp @@ -37,14 +37,12 @@ ProgressIndicator::ProgressIndicator() : ImageSet *const images = Theme::getImageSetFromTheme( "progress-indicator.png", 32, 32); - Animation *const anim = new Animation; if (images) { + Animation *const anim = new Animation; for (ImageSet::size_type i = 0, sz = images->size(); i < sz; ++i) anim->addFrame(images->get(i), 100, 0, 0, 100); - mIndicator = new SimpleAnimation(anim); - images->decRef(); } diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 838e5dad2..6d15c5520 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -412,7 +412,7 @@ void ScrollArea::drawButton(gcn::Graphics *const graphics, default: logger->log("ScrollArea::drawButton unknown dir: " + toString(static_cast(dir))); - break; + return; } if (buttons[dir][state]) @@ -450,7 +450,7 @@ void ScrollArea::calcButton(gcn::Graphics *const graphics, default: logger->log("ScrollArea::drawButton unknown dir: " + toString(static_cast(dir))); - break; + return; } if (buttons[dir][state]) diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index bb9e12320..54ed4764f 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -86,6 +86,11 @@ Window::Window(const std::string &caption, const bool modal, { logger->log("Window::Window(\"%s\")", caption.c_str()); +#ifndef USE_INTERNALGUICHAN + mDragOffsetX = 0; + mDragOffsetY = 0; +#endif + if (!windowContainer) throw GCN_EXCEPTION("Window::Window(): no windowContainer set"); -- cgit v1.2.3-70-g09d2