diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-10-11 14:48:19 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-10-11 15:24:57 +0300 |
commit | f1b82c1b06604c2c1eed750a6c980aa0b5355560 (patch) | |
tree | 3e524583691af0e5a17e5ee974439b4c6ea07ef4 /src | |
parent | 452f2489bf3225235797ea08ea0d466f80409a87 (diff) | |
download | manaplus-f1b82c1b06604c2c1eed750a6c980aa0b5355560.tar.gz manaplus-f1b82c1b06604c2c1eed750a6c980aa0b5355560.tar.bz2 manaplus-f1b82c1b06604c2c1eed750a6c980aa0b5355560.tar.xz manaplus-f1b82c1b06604c2c1eed750a6c980aa0b5355560.zip |
First part of checks from Parasoft C++ Test.
Diffstat (limited to 'src')
-rw-r--r-- | src/animatedsprite.cpp | 2 | ||||
-rw-r--r-- | src/being/being.cpp | 3 | ||||
-rw-r--r-- | src/being/localplayer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/characterviewnormal.cpp | 4 | ||||
-rw-r--r-- | src/gui/widgets/scrollarea.cpp | 18 | ||||
-rw-r--r-- | src/gui/widgets/skillmodel.cpp | 5 | ||||
-rw-r--r-- | src/gui/widgets/tabs/chattab.cpp | 3 | ||||
-rw-r--r-- | src/gui/widgets/tabs/setup_colors.cpp | 3 | ||||
-rw-r--r-- | src/gui/windows/chatwindow.cpp | 12 | ||||
-rw-r--r-- | src/gui/windows/debugwindow.cpp | 14 | ||||
-rw-r--r-- | src/gui/windows/statuswindow.cpp | 8 | ||||
-rw-r--r-- | src/gui/windows/whoisonline.cpp | 3 | ||||
-rw-r--r-- | src/guichan/widgets/scrollarea.cpp | 57 | ||||
-rw-r--r-- | src/net/download.cpp | 17 | ||||
-rw-r--r-- | src/net/messagein.cpp | 35 | ||||
-rw-r--r-- | src/net/tmwa/beinghandler.cpp | 26 | ||||
-rw-r--r-- | src/render/mobileopenglgraphics.cpp | 8 | ||||
-rw-r--r-- | src/render/sdlgraphics.cpp | 11 | ||||
-rw-r--r-- | src/text.cpp | 2 |
19 files changed, 139 insertions, 94 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 8940b1060..38f1a297b 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -209,7 +209,7 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) { fail = true; } - if ((mFrame->type == Frame::LABEL + else if ((mFrame->type == Frame::LABEL && !mFrame->nextAction.empty())) { fail = false; diff --git a/src/being/being.cpp b/src/being/being.cpp index 94e94161e..03ed2ad89 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -1849,7 +1849,8 @@ void Being::updateColors() { mNameColor = &userPalette->getColor(UserPalette::MONSTER); } - else if (mParty && mParty == player_node->getParty()) + else if (mParty && player_node + && mParty == player_node->getParty()) { mNameColor = &userPalette->getColor(UserPalette::PARTY); } diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 787d59038..ee77c9831 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -258,7 +258,7 @@ void LocalPlayer::logic() { MessagePair info = mMessages.front(); - if (particleEngine) + if (particleEngine && gui) { particleEngine->addTextRiseFadeOutEffect( info.first, diff --git a/src/gui/widgets/characterviewnormal.cpp b/src/gui/widgets/characterviewnormal.cpp index 50dd8f7e4..7e6fe380d 100644 --- a/src/gui/widgets/characterviewnormal.cpp +++ b/src/gui/widgets/characterviewnormal.cpp @@ -45,9 +45,9 @@ CharacterViewNormal::CharacterViewNormal(CharSelectDialog *const widget, character->setVisible(true); } show(0); + const CharacterDisplay *const firtChar = (*mCharacterEntries)[0]; + setWidth(firtChar->getWidth() * 5 + mPadding * 2); } - const CharacterDisplay *const firtChar = (*mCharacterEntries)[0]; - setWidth(firtChar->getWidth() * 5 + mPadding * 2); setHeight(210 + config.getIntValue("fontSize") * 2); } diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index e40b1ce18..3d79a2a2e 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -639,8 +639,12 @@ void ScrollArea::widgetResized(const gcn::Event &event A_UNUSED) { mRedraw = true; const unsigned int frameSize = 2 * mFrameSize; - getContent()->setSize(mDimension.width - frameSize, - mDimension.height - frameSize); + gcn::Widget *const content = getContent(); + if (content) + { + content->setSize(mDimension.width - frameSize, + mDimension.height - frameSize); + } } void ScrollArea::widgetMoved(const gcn::Event& event A_UNUSED) @@ -915,15 +919,11 @@ gcn::Rectangle ScrollArea::getVerticalMarkerDimension() if (length > height) length = height; - if (getVerticalMaxScroll() != 0) - { - pos = ((height - length) * mVScroll) - / getVerticalMaxScroll(); - } + const int maxScroll = getVerticalMaxScroll(); + if (maxScroll != 0) + pos = ((height - length) * mVScroll) / maxScroll; else - { pos = 0; - } } return gcn::Rectangle(mDimension.width - mScrollbarWidth, h2 + pos, diff --git a/src/gui/widgets/skillmodel.cpp b/src/gui/widgets/skillmodel.cpp index c4d79e450..fab83cb46 100644 --- a/src/gui/widgets/skillmodel.cpp +++ b/src/gui/widgets/skillmodel.cpp @@ -43,8 +43,9 @@ SkillInfo *SkillModel::getSkillAt(const int i) const std::string SkillModel::getElementAt(int i) { - if (getSkillAt(i)) - return getSkillAt(i)->data->name; + const SkillInfo *const info = getSkillAt(i); + if (info) + return info->data->name; else return std::string(); } diff --git a/src/gui/widgets/tabs/chattab.cpp b/src/gui/widgets/tabs/chattab.cpp index b4a8cb158..2659ab7f9 100644 --- a/src/gui/widgets/tabs/chattab.cpp +++ b/src/gui/widgets/tabs/chattab.cpp @@ -331,6 +331,9 @@ void ChatTab::chatLog(std::string line, Own own, void ChatTab::chatLog(const std::string &nick, std::string msg) { + if (!player_node) + return; + const Own byWho = (nick == player_node->getName() ? BY_PLAYER : BY_OTHER); if (byWho == BY_OTHER && config.getBoolValue("removeColors")) msg = removeColors(msg); diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp index 13303bd88..c29da4a8a 100644 --- a/src/gui/widgets/tabs/setup_colors.cpp +++ b/src/gui/widgets/tabs/setup_colors.cpp @@ -279,7 +279,8 @@ void Setup_Colors::valueChanged(const gcn::SelectionEvent &event A_UNUSED) break; case UserPalette::ATTACK_RANGE_BORDER: case UserPalette::HOME_PLACE_BORDER: - mTextPreview->setFont(gui->getFont()); + if (gui) + mTextPreview->setFont(gui->getFont()); mTextPreview->setTextColor(col); mTextPreview->setOutline(false); mTextPreview->setShadow(false); diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index 353212025..9a7a348c8 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -1445,16 +1445,8 @@ void ChatWindow::resortChatLog(std::string line, Own own, } else if (mShowAllLang) { - if (langChatTab) - { - langChatTab->chatLog(prefix + line, own, - ignoreRecord, tryRemoveColors); - } - else if (localChatTab) - { - localChatTab->chatLog(prefix + line, own, - ignoreRecord, tryRemoveColors); - } + langChatTab->chatLog(prefix + line, own, + ignoreRecord, tryRemoveColors); } } else if (localChatTab && channel.empty()) diff --git a/src/gui/windows/debugwindow.cpp b/src/gui/windows/debugwindow.cpp index 90a8fccd6..24a77a402 100644 --- a/src/gui/windows/debugwindow.cpp +++ b/src/gui/windows/debugwindow.cpp @@ -531,9 +531,17 @@ NetDebugTab::NetDebugTab(const Widget2 *const widget) : void NetDebugTab::logic() { BLOCK_START("NetDebugTab::logic") - // TRANSLATORS: debug window label - mPingLabel->setCaption(strprintf(_("Ping: %s ms"), - player_node->getPingTime().c_str())); + if (player_node) + { + // TRANSLATORS: debug window label + mPingLabel->setCaption(strprintf(_("Ping: %s ms"), + player_node->getPingTime().c_str())); + } + else + { + // TRANSLATORS: debug window label + mPingLabel->setCaption(strprintf(_("Ping: %s ms"), "0")); + } // TRANSLATORS: debug window label mInPackets1Label->setCaption(strprintf(_("In: %d bytes/s"), PacketCounters::getInBytes())); diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp index bbc4558b0..87dc94e8e 100644 --- a/src/gui/windows/statuswindow.cpp +++ b/src/gui/windows/statuswindow.cpp @@ -598,8 +598,12 @@ void StatusWindow::updateWeightBar(ProgressBar *const bar) const int totalWeight = PlayerInfo::getAttribute( PlayerInfo::TOTAL_WEIGHT); const int maxWeight = PlayerInfo::getAttribute(PlayerInfo::MAX_WEIGHT); - const float progress = static_cast<float>(totalWeight) - / static_cast<float>(maxWeight); + float progress = 1.0F; + if (maxWeight) + { + progress = static_cast<float>(totalWeight) + / static_cast<float>(maxWeight); + } bar->setText(strprintf("%s/%s", Units::formatWeight( totalWeight).c_str(), Units::formatWeight(maxWeight).c_str())); bar->setProgress(progress); diff --git a/src/gui/windows/whoisonline.cpp b/src/gui/windows/whoisonline.cpp index e7c60bb39..68979a682 100644 --- a/src/gui/windows/whoisonline.cpp +++ b/src/gui/windows/whoisonline.cpp @@ -329,6 +329,9 @@ void WhoIsOnline::loadWebList() // Reallocate and include terminating 0 character mMemoryBuffer = static_cast<char*>( realloc(mMemoryBuffer, mDownloadedBytes + 1)); + if (!mMemoryBuffer) + return; + mMemoryBuffer[mDownloadedBytes] = '\0'; mBrowserBox->clearRows(); diff --git a/src/guichan/widgets/scrollarea.cpp b/src/guichan/widgets/scrollarea.cpp index 6874e41c9..324afece8 100644 --- a/src/guichan/widgets/scrollarea.cpp +++ b/src/guichan/widgets/scrollarea.cpp @@ -244,11 +244,12 @@ namespace gcn { checkPolicies(); - if (!getContent()) + const Widget *const content = getContent(); + if (!content) return 0; - const int value = getContent()->getWidth() - getChildrenArea().width + - 2 * getContent()->getFrameSize(); + const int value = content->getWidth() - getChildrenArea().width + + 2 * content->getFrameSize(); if (value < 0) return 0; @@ -260,13 +261,14 @@ namespace gcn { checkPolicies(); - if (!getContent()) + const Widget *const content = getContent(); + if (!content) return 0; int value; - value = getContent()->getHeight() - getChildrenArea().height + - 2 * getContent()->getFrameSize(); + value = content->getHeight() - getChildrenArea().height + + 2 * content->getFrameSize(); if (value < 0) return 0; @@ -347,11 +349,12 @@ namespace gcn setVerticalScrollAmount(getVerticalScrollAmount()); setHorizontalScrollAmount(getHorizontalScrollAmount()); - if (getContent()) + Widget *const content = getContent(); + if (content) { - getContent()->setPosition(-mHScroll + getContent()->getFrameSize(), - -mVScroll + getContent()->getFrameSize()); - getContent()->logic(); + const int frameSize = content->getFrameSize(); + content->setPosition(-mHScroll + frameSize, -mVScroll + frameSize); + content->logic(); } BLOCK_END("ScrollArea::logic") } @@ -364,7 +367,8 @@ namespace gcn mHBarVisible = false; mVBarVisible = false; - if (!getContent()) + const Widget *const content = getContent(); + if (!content) { mHBarVisible = (mHPolicy == SHOW_ALWAYS); mVBarVisible = (mVPolicy == SHOW_ALWAYS); @@ -374,26 +378,26 @@ namespace gcn if (mHPolicy == SHOW_AUTO && mVPolicy == SHOW_AUTO) { - if (getContent()->getWidth() <= w - && getContent()->getHeight() <= h) + if (content->getWidth() <= w + && content->getHeight() <= h) { mHBarVisible = false; mVBarVisible = false; } - if (getContent()->getWidth() > w) + if (content->getWidth() > w) { mHBarVisible = true; } - if ((getContent()->getHeight() > h) - || (mHBarVisible && getContent()->getHeight() + if ((content->getHeight() > h) + || (mHBarVisible && content->getHeight() > h - mScrollbarWidth)) { mVBarVisible = true; } - if (mVBarVisible && getContent()->getWidth() > w - mScrollbarWidth) + if (mVBarVisible && content->getWidth() > w - mScrollbarWidth) mHBarVisible = true; return; @@ -412,11 +416,11 @@ namespace gcn case SHOW_AUTO: if (mVPolicy == SHOW_NEVER) { - mHBarVisible = (getContent()->getWidth() > w); + mHBarVisible = (content->getWidth() > w); } else // (mVPolicy == SHOW_ALWAYS) { - mHBarVisible = (getContent()->getWidth() + mHBarVisible = (content->getWidth() > w - mScrollbarWidth); } break; @@ -438,11 +442,11 @@ namespace gcn case SHOW_AUTO: if (mHPolicy == SHOW_NEVER) { - mVBarVisible = (getContent()->getHeight() > h); + mVBarVisible = (content->getHeight() > h); } else // (mHPolicy == SHOW_ALWAYS) { - mVBarVisible = (getContent()->getHeight() + mVBarVisible = (content->getHeight() > h - mScrollbarWidth); } break; @@ -465,15 +469,16 @@ namespace gcn void ScrollArea::showWidgetPart(Widget* widget, Rectangle area) { - if (widget != getContent()) + const Widget *const content = getContent(); + if (widget != content) throw GCN_EXCEPTION("Widget not content widget"); BasicContainer::showWidgetPart(widget, area); - setHorizontalScrollAmount(getContent()->getFrameSize() - - getContent()->getX()); - setVerticalScrollAmount(getContent()->getFrameSize() - - getContent()->getY()); + setHorizontalScrollAmount(content->getFrameSize() + - content->getX()); + setVerticalScrollAmount(content->getFrameSize() + - content->getY()); } Widget *ScrollArea::getWidgetAt(int x, int y) diff --git a/src/net/download.cpp b/src/net/download.cpp index 9dd90a1d1..fad1ec0b4 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -69,7 +69,8 @@ Download::Download(void *const ptr, const std::string &url, mError(static_cast<char*>(calloc(CURL_ERROR_SIZE + 1, 1))), mIgnoreError(ignoreError) { - mError[0] = 0; + if (mError) + mError[0] = 0; mOptions.cancel = 0; mOptions.memoryWrite = 0; @@ -117,6 +118,8 @@ unsigned long Download::fadler32(FILE *const file) // Calculate Adler-32 checksum char *const buffer = static_cast<char*>(malloc(fileSize)); + if (!buffer) + return 0; const uInt read = static_cast<uInt>(fread(buffer, 1, fileSize, file)); unsigned long adler = adler32(0L, Z_NULL, 0); adler = adler32(static_cast<uInt>(adler), @@ -174,7 +177,8 @@ bool Download::start() if (!mThread) { logger->log1(DOWNLOAD_ERROR_MESSAGE_THREAD); - strcpy(mError, DOWNLOAD_ERROR_MESSAGE_THREAD); + if (mError) + strcpy(mError, DOWNLOAD_ERROR_MESSAGE_THREAD); mUpdateFunction(mPtr, DOWNLOAD_STATUS_THREAD_ERROR, 0, 0); if (!mIgnoreError) return false; @@ -290,9 +294,14 @@ int Download::downloadThread(void *ptr) break; case CURLE_COULDNT_CONNECT: default: - logger->log("curl error %d: %s host: %s", - res, d->mError, d->mUrl.c_str()); + { + if (d->mError) + { + logger->log("curl error %d: %s host: %s", + res, d->mError, d->mUrl.c_str()); + } break; + } } if (d->mOptions.cancel) diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 219ef8a2f..28a16cfbd 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -121,13 +121,21 @@ void MessageIn::readCoordinates(uint16_t &x, uint16_t &y, uint8_t &direction) serverDir = static_cast<uint8_t>(data[2] & 0x000f); direction = fromServerDirection(serverDir); + + DEBUGLOG(std::string("readCoordinates: ").append(toString( + static_cast<int>(x))).append(",").append(toString( + static_cast<int>(y))).append(",").append(toString( + static_cast<int>(serverDir)))); + } + else + { + x = 0; + y = 0; + direction = 0; + logger->log("error: wrong readCoordinates packet"); } mPos += 3; PacketCounters::incInBytes(3); - DEBUGLOG(std::string("readCoordinates: ").append(toString( - static_cast<int>(x))).append(",").append(toString( - static_cast<int>(y))).append(",").append(toString( - static_cast<int>(serverDir)))); } void MessageIn::readCoordinatePair(uint16_t &srcX, uint16_t &srcY, @@ -146,13 +154,22 @@ void MessageIn::readCoordinatePair(uint16_t &srcX, uint16_t &srcY, temp = MAKEWORD(data[2], data[1] & 0x003f); srcY = static_cast<uint16_t>(temp >> 4); + + DEBUGLOG(std::string("readCoordinatePair: ").append(toString( + static_cast<int>(srcX))).append(",").append(toString( + static_cast<int>(srcY))).append(" ").append(toString( + static_cast<int>(dstX))).append(",").append(toString( + static_cast<int>(dstY)))); + } + else + { + srcX = 0; + srcY = 0; + dstX = 0; + dstY = 0; + logger->log("error: wrong readCoordinatePair packet"); } mPos += 5; - DEBUGLOG(std::string("readCoordinatePair: ").append(toString( - static_cast<int>(srcX))).append(",").append(toString( - static_cast<int>(srcY))).append(" ").append(toString( - static_cast<int>(dstX))).append(",").append(toString( - static_cast<int>(dstY)))); PacketCounters::incInBytes(5); } diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index b127517ea..0f668d162 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -667,22 +667,24 @@ void BeingHandler::processBeingMove3(Net::MessageIn &msg) const int16_t y = msg.readInt16(); const unsigned char *moves = msg.readBytes(len); Path path; - for (int f = 0; f < len; f ++) + if (moves) { - const unsigned char dir = moves[f]; - if (dir <= 7) + for (int f = 0; f < len; f ++) { - x += dirx[dir]; - y += diry[dir]; - path.push_back(Position(x, y)); - } - else - { - logger->log("bad move packet: %d", dir); + const unsigned char dir = moves[f]; + if (dir <= 7) + { + x += dirx[dir]; + y += diry[dir]; + path.push_back(Position(x, y)); + } + else + { + logger->log("bad move packet: %d", dir); + } } + delete [] moves; } - - delete [] moves; dstBeing->setPath(path); } diff --git a/src/render/mobileopenglgraphics.cpp b/src/render/mobileopenglgraphics.cpp index b5e1cb883..972bcc89a 100644 --- a/src/render/mobileopenglgraphics.cpp +++ b/src/render/mobileopenglgraphics.cpp @@ -905,15 +905,17 @@ SDL_Surface* MobileOpenGLGraphics::getScreenshot() if (SDL_MUSTLOCK(screenshot)) SDL_LockSurface(screenshot); + const unsigned int lineSize = 3 * w; + GLubyte *const buf = static_cast<GLubyte*>(malloc(lineSize)); + if (!buf) + return nullptr; + // Grap the pixel buffer and write it to the SDL surface glGetIntegerv(GL_PACK_ALIGNMENT, &pack); glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, screenshot->pixels); // Flip the screenshot, as OpenGL has 0,0 in bottom left - const unsigned int lineSize = 3 * w; - GLubyte *const buf = static_cast<GLubyte*>(malloc(lineSize)); - const int h2 = h / 2; for (int i = 0; i < h2; i++) { diff --git a/src/render/sdlgraphics.cpp b/src/render/sdlgraphics.cpp index 4df797762..3cba46abe 100644 --- a/src/render/sdlgraphics.cpp +++ b/src/render/sdlgraphics.cpp @@ -677,13 +677,10 @@ int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *const src, if (w > 0 && h > 0) { - if (srcrect) - { - srcrect->x = static_cast<int16_t>(srcx); - srcrect->y = static_cast<int16_t>(srcy); - srcrect->w = static_cast<int16_t>(w); - srcrect->h = static_cast<int16_t>(h); - } + srcrect->x = static_cast<int16_t>(srcx); + srcrect->y = static_cast<int16_t>(srcy); + srcrect->w = static_cast<int16_t>(w); + srcrect->h = static_cast<int16_t>(h); dstrect->w = static_cast<int16_t>(w); dstrect->h = static_cast<int16_t>(h); diff --git a/src/text.cpp b/src/text.cpp index a2cd492c2..205e945ac 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -43,7 +43,7 @@ Text::Text(const std::string &text, const int x, const int y, const gcn::Graphics::Alignment alignment, const gcn::Color* color, const bool isSpeech, gcn::Font *const font) : - mFont(font ? font : gui->getFont()), + mFont(font ? font : (gui ? gui->getFont() : nullptr)), mX(x), mY(y), mWidth(mFont->getWidth(text)), |