From 81db0022e50e25d922ac7d67d9ec6017b8856f13 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 25 Feb 2012 21:28:51 +0300 Subject: Fix old casts. --- src/being.cpp | 2 +- src/configuration.cpp | 3 ++- src/graphics.cpp | 23 +++++++++++++-------- src/gui/charcreatedialog.cpp | 10 +++++++-- src/gui/debugwindow.cpp | 2 +- src/gui/editserverdialog.cpp | 3 ++- src/gui/equipmentwindow.cpp | 10 +++++++-- src/gui/itempopup.cpp | 2 +- src/gui/outfitwindow.cpp | 2 +- src/gui/popupmenu.cpp | 2 +- src/gui/serverdialog.cpp | 4 ++-- src/gui/setup_relations.cpp | 2 +- src/gui/updaterwindow.cpp | 4 ++-- src/gui/viewport.cpp | 3 ++- src/gui/widgets/browserbox.cpp | 22 ++++++++++---------- src/gui/widgets/guitable.cpp | 9 ++++---- src/gui/widgets/setupitem.cpp | 4 ++-- src/gui/widgets/textfield.cpp | 2 +- src/guichan/include/guichan/sdl/sdlpixel.hpp | 4 ++-- src/guichan/sdl/sdlgraphics.cpp | 23 ++++++++++++++------- src/guichan/sdl/sdlimage.cpp | 4 ++-- src/guichan/widgets/scrollarea.cpp | 8 +++---- src/guichan/widgets/slider.cpp | 4 ++-- src/guichan/widgets/tabbedarea.cpp | 2 +- src/guichan/widgets/textbox.cpp | 31 ++++++++++++++-------------- src/guichan/widgets/window.cpp | 2 +- src/guildmanager.cpp | 6 +++--- src/localplayer.cpp | 2 +- src/net/messagein.cpp | 2 +- src/net/tmwa/playerhandler.cpp | 4 ++-- src/opengl1graphics.cpp | 6 ++++-- src/openglgraphics.cpp | 10 +++++---- src/utils/copynpaste.cpp | 10 +++++++-- src/utils/langs.cpp | 8 +++---- src/utils/physfsrwops.cpp | 22 ++++++++++---------- src/utils/process.cpp | 6 +++--- src/utils/stringutils.cpp | 6 +++--- 37 files changed, 153 insertions(+), 116 deletions(-) diff --git a/src/being.cpp b/src/being.cpp index e1cb9b0ae..b5f55592f 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -2320,7 +2320,7 @@ void Being::recalcSpritesOrder() int val = slotRemap.at(slot); int id = 0; - if ((int)mSpriteIDs.size() > val) + if (static_cast(mSpriteIDs.size()) > val) id = mSpriteIDs[val]; int idx = -1; diff --git a/src/configuration.cpp b/src/configuration.cpp index 694f94e78..97540c385 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -572,7 +572,8 @@ void ConfigurationObject::writeToXML(XmlTextWriterPtr writer) elt_it != it->second.end(); ++elt_it) { xmlTextWriterStartElement(writer, BAD_CAST name); - (*elt_it)->writeToXML(writer); + if (*elt_it) + (*elt_it)->writeToXML(writer); xmlTextWriterEndElement(writer); } diff --git a/src/graphics.cpp b/src/graphics.cpp index 5241bbcc6..e6841fa5c 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -845,7 +845,8 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) case 1: for (y = y1; y < y2; y++) { - Uint8 *p = (Uint8 *)mTarget->pixels + y * mTarget->pitch; + Uint8 *p = static_cast(mTarget->pixels) + + y * mTarget->pitch; for (x = x1; x < x2; x++) *(p + x) = pixel; } @@ -853,12 +854,14 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) case 2: for (y = y1; y < y2; y++) { - Uint8 *p0 = (Uint8 *)mTarget->pixels + y * mTarget->pitch; + Uint8 *p0 = static_cast(mTarget->pixels) + + y * mTarget->pitch; for (x = x1; x < x2; x++) { Uint8 *p = p0 + x * 2; - *(Uint16 *)p = gcn::SDLAlpha16( - pixel, *(Uint32 *)p, mColor.a, mTarget->format); + *reinterpret_cast(p) = gcn::SDLAlpha16( + pixel, *reinterpret_cast(p), + mColor.a, mTarget->format); } } break; @@ -871,7 +874,8 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) for (y = y1; y < y2; y++) { - Uint8 *p0 = (Uint8 *)mTarget->pixels + y * mTarget->pitch; + Uint8 *p0 = static_cast(mTarget->pixels) + + y * mTarget->pitch; for (x = x1; x < x2; x++) { Uint8 *p = p0 + x * 3; @@ -896,18 +900,19 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) const unsigned a1 = (255 - mColor.a); for (y = y1; y < y2; y++) { - Uint8 *p0 = (Uint8 *)mTarget->pixels + y * mTarget->pitch; + Uint8 *p0 = static_cast(mTarget->pixels) + + y * mTarget->pitch; for (x = x1; x < x2; x++) { Uint8 *p = p0 + x * 4; - Uint32 dst = *(Uint32 *)p; + Uint32 dst = *reinterpret_cast(p); const unsigned int b = (pb + (dst & 0xff) * a1) >> 8; const unsigned int g = (pg + (dst & 0xff00) * a1) >> 8; const unsigned int r = (pr + (dst & 0xff0000) * a1) >> 8; - *(Uint32 *)p = ((b & 0xff) | (g & 0xff00) - | (r & 0xff0000)); + *reinterpret_cast(p) = ((b & 0xff) + | (g & 0xff00) | (r & 0xff0000)); } } break; diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 8d4767a15..9f7436ad8 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -474,8 +474,11 @@ void CharCreateDialog::updateHair() mHairStyle %= Being::getNumOfHairstyles(); if (mHairStyle < 0) mHairStyle += Being::getNumOfHairstyles(); - if (mHairStyle < (signed)minHairStyle || mHairStyle > (signed)maxHairStyle) + if (mHairStyle < static_cast(minHairStyle) + || mHairStyle > static_cast(maxHairStyle)) + { mHairStyle = minHairStyle; + } const ItemInfo &item = ItemDB::get(-mHairStyle); mHairStyleNameLabel->setCaption(item.getName()); mHairStyleNameLabel->adjustSize(); @@ -483,8 +486,11 @@ void CharCreateDialog::updateHair() mHairColor %= ColorDB::getHairSize(); if (mHairColor < 0) mHairColor += ColorDB::getHairSize(); - if (mHairColor < (signed)minHairColor || mHairColor > (signed)maxHairColor) + if (mHairColor < static_cast(minHairColor) + || mHairColor > static_cast(maxHairColor)) + { mHairColor = minHairColor; + } mHairColorNameLabel->setCaption(ColorDB::getHairColorName(mHairColor)); mHairColorNameLabel->adjustSize(); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index b65068dc5..fa01b5aa8 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -390,7 +390,7 @@ void NetDebugTab::logic() if (player_node && player_node->getPingTime() != 0) { mPingLabel->setCaption(strprintf(_("Ping: %s ms"), - toString((int)player_node->getPingTime()).c_str())); + toString(static_cast(player_node->getPingTime())).c_str())); } else { diff --git a/src/gui/editserverdialog.cpp b/src/gui/editserverdialog.cpp index 8a4a9579d..53e31c3c8 100644 --- a/src/gui/editserverdialog.cpp +++ b/src/gui/editserverdialog.cpp @@ -184,7 +184,8 @@ void EditServerDialog::action(const gcn::ActionEvent &event) mServer.name = mNameField->getText(); mServer.description = mDescriptionField->getText(); mServer.hostname = mServerAddressField->getText(); - mServer.port = (short) atoi(mPortField->getText().c_str()); + mServer.port = static_cast(atoi( + mPortField->getText().c_str())); if (mTypeField) { diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 275bf19bb..89063c3dc 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -407,8 +407,11 @@ void EquipmentWindow::loadSlot(XmlNodePtr slotNode, ImageSet *imageset) const int imageIndex = XML::getProperty(slotNode, "image", -1); Image *image = nullptr; - if (imageset && imageIndex >= 0 && imageIndex < (signed)imageset->size()) + if (imageset && imageIndex >= 0 && imageIndex + < static_cast(imageset->size())) + { image = imageset->get(imageIndex); + } if (mBoxes[slot]) { @@ -510,8 +513,11 @@ void EquipmentWindow::addBox(int idx, int x, int y, int imageIndex) { Image *image = nullptr; - if (mImageSet && imageIndex >= 0 && imageIndex < (signed)mImageSet->size()) + if (mImageSet && imageIndex >= 0 && imageIndex + < static_cast(mImageSet->size())) + { image = mImageSet->get(imageIndex); + } mBoxes[idx] = new EquipmentBox(x + getPadding(), y + getTitleBarHeight(), image); diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index d96aa564f..f33f77e83 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -123,7 +123,7 @@ void ItemPopup::setItem(const Item *item, bool showImage) } mItemName->adjustSize(); unsigned minWidth = mItemName->getWidth() + 8; - if ((unsigned)getWidth() < minWidth) + if (static_cast(getWidth()) < minWidth) setWidth(minWidth); } } diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 73484f1d5..6eaa2ac4e 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -190,7 +190,7 @@ void OutfitWindow::save() outfitStr += toString(res); if (i < OUTFIT_ITEM_COUNT - 1) outfitStr += " "; - outfitColorsStr += toString((int)mItemColors[o][i]); + outfitColorsStr += toString(static_cast(mItemColors[o][i])); if (i < OUTFIT_ITEM_COUNT - 1) outfitColorsStr += " "; } diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index c987843d3..933d2c7cd 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -2205,7 +2205,7 @@ void PlayerListener::action(const gcn::ActionEvent &event) { std::string comment = mDialog->getText(); Being* being = actorSpriteManager->findBeingByName( - mNick, (ActorSprite::Type)mType); + mNick, static_cast(mType)); if (being) being->setComment(comment); Being::saveComment(mNick, comment, mType); diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index da61e105b..ed9696892 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -125,7 +125,7 @@ std::string ServersListModel::getElementAt(int elementIndex) void ServersListModel::setVersionString(int index, const std::string &version) { - if (index >= (int)mVersionStrings.size()) + if (index >= static_cast(mVersionStrings.size())) return; if (version.empty()) @@ -632,7 +632,7 @@ void ServerDialog::saveCustomServers(const ServerInfo ¤tServer, // Make sure the current server is mentioned first if (currentServer.isValid()) { - if (index >= 0 && (unsigned)index < mServers.size()) + if (index >= 0 && static_cast(index) < mServers.size()) { mServers[index] = currentServer; } diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp index 47d53620c..f3b664c9b 100644 --- a/src/gui/setup_relations.cpp +++ b/src/gui/setup_relations.cpp @@ -194,7 +194,7 @@ public: std::string getPlayerAt(int index) const { - if (index < 0 || index >= (signed)mPlayers->size()) + if (index < 0 || index >= static_cast(mPlayers->size())) return ""; return (*mPlayers)[index]; } diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index 3aaf93557..fe26d42eb 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -554,8 +554,8 @@ void UpdaterWindow::logic() if (mUpdateFiles.size() && mUpdateIndex <= mUpdateFiles.size()) { mProgressBar->setText(strprintf("%d/%d", mUpdateIndex - + mUpdateIndexOffset + 1, (int)mUpdateFiles.size() - + (int)mTempUpdateFiles.size() + 1)); + + mUpdateIndexOffset + 1, static_cast(mUpdateFiles.size()) + + static_cast(mTempUpdateFiles.size()) + 1)); } else { diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index d4c188bfb..0c0f0d3d9 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -199,7 +199,8 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) // if (debugChatTab) // debugChatTab->chatLog("incorrect player position!"); logger->log("incorrect player position: %d, %d, %d, %d", - player_x, player_y, (int)mPixelViewX, (int)mPixelViewY); + player_x, player_y, static_cast(mPixelViewX), + static_cast(mPixelViewY)); if (player_node) { logger->log("tile position: %d, %d", diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 5856a91b1..47c5616b6 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -232,15 +232,17 @@ void BrowserBox::addRow(const std::string &row, bool atTop) tempRow.substr(nextChar, (nextSpacePos - nextChar))); - if ((x + nextWordWidth + 10) > (unsigned)getWidth()) + if ((x + nextWordWidth + 10) + > static_cast(getWidth())) { x = 15; // Ident in new line y += 1; - j++; + j ++; } } // Wrapping looong lines (brutal force) - else if ((x + 2 * hyphenWidth) > (unsigned)getWidth()) + else if ((x + 2 * hyphenWidth) + > static_cast(getWidth())) { x = 15; // Ident in new line y += 1; @@ -249,7 +251,7 @@ void BrowserBox::addRow(const std::string &row, bool atTop) } setHeight(font->getHeight() * (static_cast( - mTextRows.size()) + y)); + mTextRows.size()) + y)); } else { @@ -423,7 +425,7 @@ int BrowserBox::calcHeight() if (row.find("---", 0) == 0) { const int dashWidth = fontWidthMinus; - for (x = 0; x < (unsigned)getWidth(); x++) + for (x = 0; x < static_cast(getWidth()); x ++) { mLineParts.push_back(LinePart(x, y, selColor, "-", false)); x += dashWidth - 2; @@ -557,9 +559,8 @@ int BrowserBox::calcHeight() width = font->getWidth(part); // Auto wrap mode - if (mMode == AUTO_WRAP && getWidth() > 0 - && width > 0 - && (x + width + 10) > (unsigned)getWidth()) + if (mMode == AUTO_WRAP && getWidth() > 0 && width > 0 + && (x + width + 10) > static_cast(getWidth())) { bool forced = false; @@ -592,9 +593,8 @@ int BrowserBox::calcHeight() else width = font->getWidth(part); } - while (end > start && width > 0 - && (x + width + 10) - > (unsigned)getWidth()); + while (end > start && width > 0 && (x + width + 10) + > static_cast(getWidth())); if (forced) { diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp index d620cbb8d..6434f5453 100644 --- a/src/gui/widgets/guitable.cpp +++ b/src/gui/widgets/guitable.cpp @@ -348,14 +348,15 @@ void GuiTable::draw(gcn::Graphics* graphics) if (mSelectedRow > 0) { - if (mLinewiseMode && r == (unsigned)mSelectedRow && c == 0) + if (mLinewiseMode && r == static_cast( + mSelectedRow) && c == 0) { graphics->fillRectangle(gcn::Rectangle(0, y_offset, - getWidth(), height)); + getWidth(), height)); } else if (!mLinewiseMode && mSelectedColumn > 0 - && c == (unsigned)mSelectedColumn - && r == (unsigned)mSelectedRow) + && c == static_cast(mSelectedColumn) + && r == static_cast(mSelectedRow)) { graphics->fillRectangle(gcn::Rectangle( x_offset, y_offset, width, height)); diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 490c046c3..8987719da 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -830,8 +830,8 @@ void SetupItemSlider2::updateLabel() int val = mSlider->getValue() - mMin; if (val < 0) val = 0; - else if (val >= (signed)mValues->size()) - val = (signed)mValues->size() - 1; + else if (val >= static_cast(mValues->size())) + val = static_cast(mValues->size()) - 1; std::string str = mValues->at(val); mLabel2->setCaption(str); } diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index e207b0613..a90712340 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -183,7 +183,7 @@ int TextField::getValue() const if (value < mMinimum) return mMinimum; - if (value > (signed)mMaximum) + if (value > static_cast(mMaximum)) return mMaximum; return value; diff --git a/src/guichan/include/guichan/sdl/sdlpixel.hpp b/src/guichan/include/guichan/sdl/sdlpixel.hpp index f56100b4a..23298ef37 100644 --- a/src/guichan/include/guichan/sdl/sdlpixel.hpp +++ b/src/guichan/include/guichan/sdl/sdlpixel.hpp @@ -244,8 +244,8 @@ namespace gcn break; case 2: - *reinterpret_cast(p) = SDLAlpha16(pixel, *(Uint32 *)p, - color.a, surface->format); + *reinterpret_cast(p) = SDLAlpha16(pixel, + *reinterpret_cast(p), color.a, surface->format); break; case 3: diff --git a/src/guichan/sdl/sdlgraphics.cpp b/src/guichan/sdl/sdlgraphics.cpp index c8cec6370..ae61a0432 100644 --- a/src/guichan/sdl/sdlgraphics.cpp +++ b/src/guichan/sdl/sdlgraphics.cpp @@ -283,7 +283,8 @@ namespace gcn SDL_LockSurface(mTarget); - Uint8 *p = (Uint8 *)mTarget->pixels + y * mTarget->pitch + x1 * bpp; + Uint8 *p = static_cast(mTarget->pixels) + + y * mTarget->pitch + x1 * bpp; Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r, @@ -298,7 +299,7 @@ namespace gcn case 2: { - Uint16* q = (Uint16*)p; + Uint16* q = reinterpret_cast(p); for (; x1 <= x2; ++x1) *(q++) = pixel; break; @@ -329,7 +330,7 @@ namespace gcn case 4: { - Uint32* q = (Uint32*)p; + Uint32 *q = reinterpret_cast(p); for (; x1 <= x2; ++x1) { if (mAlpha) @@ -395,7 +396,8 @@ namespace gcn SDL_LockSurface(mTarget); - Uint8 *p = (Uint8 *)mTarget->pixels + y1 * mTarget->pitch + x * bpp; + Uint8 *p = static_cast(mTarget->pixels) + + y1 * mTarget->pitch + x * bpp; Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); @@ -411,9 +413,9 @@ namespace gcn break; case 2: - for (; y1 <= y2; ++y1) + for (; y1 <= y2; ++ y1) { - *(Uint16*)p = pixel; + *reinterpret_cast(p) = pixel; p += mTarget->pitch; } break; @@ -445,9 +447,14 @@ namespace gcn for (; y1 <= y2; ++y1) { if (mAlpha) - *(Uint32*)p = SDLAlpha32(pixel, *(Uint32*)p, mColor.a); + { + *reinterpret_cast(p) = SDLAlpha32(pixel, + *reinterpret_cast(p), mColor.a); + } else - *(Uint32*)p = pixel; + { + *reinterpret_cast(p) = pixel; + } p += mTarget->pitch; } break; diff --git a/src/guichan/sdl/sdlimage.cpp b/src/guichan/sdl/sdlimage.cpp index 4f9b9565c..cf8505c4e 100644 --- a/src/guichan/sdl/sdlimage.cpp +++ b/src/guichan/sdl/sdlimage.cpp @@ -142,8 +142,8 @@ namespace gcn { Uint8 r, g, b, a; - SDL_GetRGBA(((unsigned int*)mSurface->pixels)[i], mSurface->format, - &r, &g, &b, &a); + SDL_GetRGBA((static_cast(mSurface->pixels)[i]), + mSurface->format, &r, &g, &b, &a); if (a != 255) { diff --git a/src/guichan/widgets/scrollarea.cpp b/src/guichan/widgets/scrollarea.cpp index 451288c77..21f7b5930 100644 --- a/src/guichan/widgets/scrollarea.cpp +++ b/src/guichan/widgets/scrollarea.cpp @@ -325,12 +325,12 @@ namespace gcn if (y < getVerticalMarkerDimension().y) { setVerticalScrollAmount(getVerticalScrollAmount() - - (int)(getChildrenArea().height * 0.95)); + - static_cast(getChildrenArea().height * 0.95)); } else { setVerticalScrollAmount(getVerticalScrollAmount() - + (int)(getChildrenArea().height * 0.95)); + + static_cast(getChildrenArea().height * 0.95)); } } else if (getHorizontalMarkerDimension().isPointInRect(x, y)) @@ -345,12 +345,12 @@ namespace gcn if (x < getHorizontalMarkerDimension().x) { setHorizontalScrollAmount(getHorizontalScrollAmount() - - (int)(getChildrenArea().width * 0.95)); + - static_cast(getChildrenArea().width * 0.95)); } else { setHorizontalScrollAmount(getHorizontalScrollAmount() - + (int)(getChildrenArea().width * 0.95)); + + static_cast(getChildrenArea().width * 0.95)); } } } diff --git a/src/guichan/widgets/slider.cpp b/src/guichan/widgets/slider.cpp index 16f7cd8be..36f067eab 100644 --- a/src/guichan/widgets/slider.cpp +++ b/src/guichan/widgets/slider.cpp @@ -245,7 +245,7 @@ namespace gcn else w = getHeight(); - double pos = v / ((double)w - getMarkerLength()); + double pos = v / (static_cast(w) - getMarkerLength()); return (1.0 - pos) * getScaleStart() + pos * getScaleEnd(); } @@ -257,7 +257,7 @@ namespace gcn else v = getHeight(); - int w = (int)((v - getMarkerLength()) + int w = static_cast((v - getMarkerLength()) * (value - getScaleStart()) / (getScaleEnd() - getScaleStart())); diff --git a/src/guichan/widgets/tabbedarea.cpp b/src/guichan/widgets/tabbedarea.cpp index 7af00c4c4..3e7178548 100644 --- a/src/guichan/widgets/tabbedarea.cpp +++ b/src/guichan/widgets/tabbedarea.cpp @@ -320,7 +320,7 @@ namespace gcn int index = getSelectedTabIndex(); index++; - if (index >= (int)mTabs.size()) + if (index >= static_cast(mTabs.size())) return; else setSelectedTab(mTabs[index].first); diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp index e78ea91a3..c2cd5586f 100644 --- a/src/guichan/widgets/textbox.cpp +++ b/src/guichan/widgets/textbox.cpp @@ -155,7 +155,7 @@ namespace gcn { mCaretRow = mouseEvent.getY() / getFont()->getHeight(); - if (mCaretRow >= (int)mTextRows.size()) + if (mCaretRow >= static_cast(mTextRows.size())) mCaretRow = mTextRows.size() - 1; mCaretColumn = getFont()->getStringIndexAt( @@ -193,11 +193,11 @@ namespace gcn else if (key.getValue() == Key::RIGHT) { ++mCaretColumn; - if (mCaretColumn > (int)mTextRows[mCaretRow].size()) + if (mCaretColumn > static_cast(mTextRows[mCaretRow].size())) { - ++mCaretRow; + ++ mCaretRow; - if (mCaretRow >= (int)mTextRows.size()) + if (mCaretRow >= static_cast(mTextRows.size())) { mCaretRow = mTextRows.size() - 1; if (mCaretRow < 0) @@ -254,14 +254,15 @@ namespace gcn --mCaretRow; } else if (key.getValue() == Key::DELETE - && mCaretColumn < (int)mTextRows[mCaretRow].size() - && mEditable) + && mCaretColumn < static_cast( + mTextRows[mCaretRow].size()) && mEditable) { mTextRows[mCaretRow].erase(mCaretColumn, 1); } else if (key.getValue() == Key::DELETE - && mCaretColumn == (int)mTextRows[mCaretRow].size() - && mCaretRow < ((int)mTextRows.size() - 1) + && mCaretColumn == static_cast( + mTextRows[mCaretRow].size()) + && mCaretRow < (static_cast(mTextRows.size()) - 1) && mEditable) { mTextRows[mCaretRow] += mTextRows[mCaretRow + 1]; @@ -291,7 +292,7 @@ namespace gcn / getFont()->getHeight(); mCaretRow += rowsPerPage; - if (mCaretRow >= (int)mTextRows.size()) + if (mCaretRow >= static_cast(mTextRows.size())) mCaretRow = mTextRows.size() - 1; } } @@ -305,7 +306,7 @@ namespace gcn && mEditable) { mTextRows[mCaretRow].insert(mCaretColumn, - std::string(1, (char)key.getValue())); + std::string(1, static_cast(key.getValue()))); ++ mCaretColumn; } @@ -332,9 +333,7 @@ namespace gcn void TextBox::setCaretPosition(unsigned int position) { - int row; - - for (row = 0; row < (int)mTextRows.size(); row++) + for (int row = 0; row < static_cast(mTextRows.size()); row ++) { if (position <= mTextRows[row].size()) { @@ -373,7 +372,7 @@ namespace gcn { mCaretRow = row; - if (mCaretRow >= (int)mTextRows.size()) + if (mCaretRow >= static_cast(mTextRows.size())) mCaretRow = mTextRows.size() - 1; if (mCaretRow < 0) @@ -391,7 +390,7 @@ namespace gcn { mCaretColumn = column; - if (mCaretColumn > (int)mTextRows[mCaretRow].size()) + if (mCaretColumn > static_cast(mTextRows[mCaretRow].size())) mCaretColumn = mTextRows[mCaretRow].size(); if (mCaretColumn < 0) @@ -431,7 +430,7 @@ namespace gcn int i; std::string text; - for (i = 0; i < (int)mTextRows.size() - 1; ++i) + for (i = 0; i < static_cast(mTextRows.size()) - 1; ++ i) text = text + mTextRows[i] + "\n"; text = text + mTextRows[i]; diff --git a/src/guichan/widgets/window.cpp b/src/guichan/widgets/window.cpp index d7c5809e6..c7ed8a69e 100644 --- a/src/guichan/widgets/window.cpp +++ b/src/guichan/widgets/window.cpp @@ -137,7 +137,7 @@ namespace gcn mDragOffsetX = mouseEvent.getX(); mDragOffsetY = mouseEvent.getY(); - mMoved = mouseEvent.getY() <= (int)mTitleBarHeight; + mMoved = mouseEvent.getY() <= static_cast(mTitleBarHeight); } void Window::mouseReleased(MouseEvent& mouseEvent A_UNUSED) diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp index 9dc9d7b73..08af3b2c7 100644 --- a/src/guildmanager.cpp +++ b/src/guildmanager.cpp @@ -274,7 +274,7 @@ bool GuildManager::process(std::string msg) return false; // logger->log("welcome message: %s", msg.c_str()); int pos = msg.find("! ("); - if (pos == (int)std::string::npos) + if (pos == static_cast(std::string::npos)) return false; msg = msg.substr(0, pos); guild->setName(msg); @@ -299,7 +299,7 @@ bool GuildManager::process(std::string msg) return false; pos = msg.find(", Guild:"); - if (pos == (int)std::string::npos) + if (pos == static_cast(std::string::npos)) return false; int level = atoi(msg.substr(0, pos).c_str()); @@ -310,7 +310,7 @@ bool GuildManager::process(std::string msg) msg = msg.substr(pos + strlen(", Guild:")); pos = msg.find(", No. Of Online Players: "); - if (pos == (int)std::string::npos) + if (pos == static_cast(std::string::npos)) return false; msg = msg.substr(0, pos); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index b07511196..5114f868c 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -2064,7 +2064,7 @@ std::string LocalPlayer::getQuickDropCounterString() void LocalPlayer::setQuickDropCounter(int n) { - if (n < 1 || n >= (signed)quickDropCounterSize) + if (n < 1 || n >= static_cast(quickDropCounterSize)) return; mQuickDropCounter = n; config.setValue("quickDropCounter", mQuickDropCounter); diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 0547ed337..5d15d26ac 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -265,7 +265,7 @@ unsigned char *MessageIn::readBytes(int length) #ifdef ENABLEDEBUGLOG std::string str; for (int f = 0; f < length; f ++) - str += strprintf ("%02x", (unsigned)buf[f]); + str += strprintf ("%02x", static_cast(buf[f])); str += " "; for (int f = 0; f < length; f ++) { diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index bfe9eea42..a63af770a 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -229,7 +229,7 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg) return; } - char *start = (char*)msg.readBytes(size); + char *start = reinterpret_cast(msg.readBytes(size)); if (!start) return; @@ -265,7 +265,7 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg) gender = GENDER_FEMALE; } } - arr.push_back(new OnlinePlayer((char*)buf, + arr.push_back(new OnlinePlayer(static_cast(buf), status, level, gender, ver)); buf += strlen(buf) + 1; } diff --git a/src/opengl1graphics.cpp b/src/opengl1graphics.cpp index 34e9fcda3..ea4d5e6f3 100644 --- a/src/opengl1graphics.cpp +++ b/src/opengl1graphics.cpp @@ -393,8 +393,10 @@ void OpenGL1Graphics::drawRescaledImagePattern(Image *image, int x, int y, // Draw a set of textured rectangles glBegin(GL_QUADS); - const float scaleFactorW = (float) scaledWidth / image->getWidth(); - const float scaleFactorH = (float) scaledHeight / image->getHeight(); + const float scaleFactorW = static_cast(scaledWidth) + / image->getWidth(); + const float scaleFactorH = static_cast(scaledHeight) + / image->getHeight(); for (int py = 0; py < h; py += ih) { diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index bcf46e18b..d972a738f 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -554,8 +554,10 @@ void OpenGLGraphics::drawRescaledImagePattern(Image *image, { int width = (px + scaledWidth >= w) ? w - px : scaledWidth; int dstX = x + px; - const float visibleFractionW = (float) width / scaledWidth; - const float visibleFractionH = (float) height / scaledHeight; + const float visibleFractionW = static_cast(width) + / scaledWidth; + const float visibleFractionH = static_cast(height) + / scaledHeight; const float texX2 = texX1 + tFractionW * visibleFractionW; const float texY2 = texY1 + tFractionH * visibleFractionH; @@ -597,8 +599,8 @@ void OpenGLGraphics::drawRescaledImagePattern(Image *image, } else { - const float scaleFactorW = (float) scaledWidth / iw; - const float scaleFactorH = (float) scaledHeight / ih; + const float scaleFactorW = static_cast(scaledWidth) / iw; + const float scaleFactorH = static_cast(scaledHeight) / ih; for (int py = 0; py < h; py += scaledHeight) { diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp index 90e0c5c93..763b579d0 100644 --- a/src/utils/copynpaste.cpp +++ b/src/utils/copynpaste.cpp @@ -442,9 +442,15 @@ bool runxsel(std::string& text, const char *p1, const char *p2) close(fd[0]); } if (p2) - execl("/usr/bin/xsel", "xsel", p1, p2, (char *)nullptr); + { + execl("/usr/bin/xsel", "xsel", p1, p2, + static_cast(nullptr)); + } else - execl("/usr/bin/xsel", "xsel", p1, (char *)nullptr); + { + execl("/usr/bin/xsel", "xsel", p1, + static_cast(nullptr)); + } exit(1); } diff --git a/src/utils/langs.cpp b/src/utils/langs.cpp index 2efbd781a..c1f9f7ecf 100644 --- a/src/utils/langs.cpp +++ b/src/utils/langs.cpp @@ -44,11 +44,11 @@ std::vector getLang() } int dot = lang.find("."); - if (dot != (signed)std::string::npos) + if (dot != static_cast(std::string::npos)) lang = lang.substr(0, dot); langs.push_back(lang); dot = lang.find("_"); - if (dot != (signed)std::string::npos) + if (dot != static_cast(std::string::npos)) langs.push_back(lang.substr(0, dot)); return langs; } @@ -78,10 +78,10 @@ std::string getLangShort() } int dot = lang.find("."); - if (dot != (signed)std::string::npos) + if (dot != static_cast(std::string::npos)) lang = lang.substr(0, dot); dot = lang.find("_"); - if (dot != (signed)std::string::npos) + if (dot != static_cast(std::string::npos)) return lang.substr(0, dot); return lang; } diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp index 1960f0dee..2675b89ae 100644 --- a/src/utils/physfsrwops.cpp +++ b/src/utils/physfsrwops.cpp @@ -29,7 +29,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) { - PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1; + PHYSFS_file *handle = static_cast(rw->hidden.unknown.data1); int pos = 0; if (whence == SEEK_SET) @@ -46,8 +46,8 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) return -1; } /* if */ - pos = (int)current; - if (((PHYSFS_sint64)pos) != current) + pos = static_cast(current); + if (static_cast(pos) != current) { SDL_SetError("Can't fit current file position in an int!"); return -1; @@ -67,8 +67,8 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) return -1; } /* if */ - pos = (int)len; - if (((PHYSFS_sint64)pos) != len) + pos = static_cast(len); + if (static_cast(pos) != len) { SDL_SetError("Can't fit end-of-file position in an int!"); return -1; @@ -88,7 +88,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) return -1; } /* if */ - if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos)) + if (!PHYSFS_seek(handle, static_cast(pos))) { SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); return -1; @@ -99,7 +99,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence) static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum) { - PHYSFS_file *handle = (PHYSFS_file*)rw->hidden.unknown.data1; + PHYSFS_file *handle = static_cast(rw->hidden.unknown.data1); PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum); if (rc != maxnum) { @@ -107,22 +107,22 @@ static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum) SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); } /* if */ - return (int)rc; + return static_cast(rc); } /* physfsrwops_read */ static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num) { - PHYSFS_file *handle = (PHYSFS_file*)rw->hidden.unknown.data1; + PHYSFS_file *handle = static_cast(rw->hidden.unknown.data1); PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num); if (rc != num) SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); - return (int) rc; + return static_cast(rc); } /* physfsrwops_write */ static int physfsrwops_close(SDL_RWops *rw) { - PHYSFS_file *handle = (PHYSFS_file*)rw->hidden.unknown.data1; + PHYSFS_file *handle = static_cast(rw->hidden.unknown.data1); if (!PHYSFS_close(handle)) { SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); diff --git a/src/utils/process.cpp b/src/utils/process.cpp index fd0ec0fa8..0106c597d 100644 --- a/src/utils/process.cpp +++ b/src/utils/process.cpp @@ -112,12 +112,12 @@ int execFile(std::string pathName, std::string name, if (arg2.empty()) { execl(pathName.c_str(), name.c_str(), - arg1.c_str(), (char *)nullptr); + arg1.c_str(), static_cast(nullptr)); } else { - execl(pathName.c_str(), name.c_str(), - arg1.c_str(), arg2.c_str(), (char *)nullptr); + execl(pathName.c_str(), name.c_str(), arg1.c_str(), + arg2.c_str(), static_cast(nullptr)); } exit(-1); } diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 2f478a909..5a7ea87fd 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -522,9 +522,9 @@ std::string stringToHexPath(const std::string &str) if (str.empty()) return ""; - std::string hex = strprintf("%%%2x/", (int)str[0]); + std::string hex = strprintf("%%%2x/", static_cast(str[0])); for (unsigned f = 1; f < str.size(); f ++) - hex += strprintf("%%%2x", (int)str[f]); + hex += strprintf("%%%2x", static_cast(str[f])); return hex; } @@ -600,7 +600,7 @@ bool findCutFirst(std::string &str1, std::string str2) std::string &removeProtocol(std::string &url) { int i = url.find("://"); - if (i != (int)std::string::npos) + if (i != static_cast(std::string::npos)) url = url.substr(i + 3); return url; } -- cgit v1.2.3-70-g09d2