From dc0f7bf903421c59e7e19da4826c1775d7e6a424 Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Mon, 18 Apr 2016 17:52:58 +0800 Subject: [PATCH] Fixes format warnings. --- cocos/network/SocketIO.cpp | 2 +- cocos/network/WebSocket.cpp | 2 +- cocos/renderer/CCTexture2D.cpp | 10 +++++----- extensions/assets-manager/AssetsManagerEx.cpp | 2 +- .../Classes/Box2DTestBed/Box2dView.cpp | 4 ++-- .../Classes/Camera3DTest/Camera3DTest.cpp | 4 ++-- .../CCControlButtonTest.cpp | 2 +- .../NetworkTest/WebSocketTest.cpp | 6 +++--- .../TableViewTest/TableViewTestScene.cpp | 4 ++-- .../Classes/Sprite3DTest/Sprite3DTest.cpp | 2 +- .../Classes/Texture2dTest/Texture2dTest.cpp | 4 ++-- .../UIPageViewTest/UIPageViewTest.cpp | 18 +++++++++--------- .../UIRichTextTest/UIRichTextTest.cpp | 4 ++-- 13 files changed, 32 insertions(+), 32 deletions(-) diff --git a/cocos/network/SocketIO.cpp b/cocos/network/SocketIO.cpp index 62cd820813..9baf1f8e8a 100644 --- a/cocos/network/SocketIO.cpp +++ b/cocos/network/SocketIO.cpp @@ -994,7 +994,7 @@ void SIOClientImpl::onClose(WebSocket* ws) void SIOClientImpl::onError(WebSocket* ws, const WebSocket::ErrorCode& error) { CC_UNUSED_PARAM(ws); - CCLOGERROR("Websocket error received: %d", error); + CCLOGERROR("Websocket error received: %d", static_cast(error)); } //begin SIOClient methods diff --git a/cocos/network/WebSocket.cpp b/cocos/network/WebSocket.cpp index 917804e33e..ef571822b3 100644 --- a/cocos/network/WebSocket.cpp +++ b/cocos/network/WebSocket.cpp @@ -558,7 +558,7 @@ void WebSocket::onSubThreadLoop() } else { - LOGD("Ready state is closing or was closed, code=%d, quit websocket thread!\n", _readyState); + LOGD("Ready state is closing or was closed, code=%d, quit websocket thread!\n", static_cast(_readyState)); _readStateMutex.unlock(); _wsHelper->quitWebSocketThread(); } diff --git a/cocos/renderer/CCTexture2D.cpp b/cocos/renderer/CCTexture2D.cpp index cdf0361365..740963bfa4 100644 --- a/cocos/renderer/CCTexture2D.cpp +++ b/cocos/renderer/CCTexture2D.cpp @@ -846,7 +846,7 @@ Texture2D::PixelFormat Texture2D::convertI8ToFormat(const unsigned char* data, s // unsupported conversion or don't need to convert if (format != PixelFormat::AUTO && format != PixelFormat::I8) { - CCLOG("Can not convert image format PixelFormat::I8 to format ID:%d, we will use it's origin format PixelFormat::I8", format); + CCLOG("Can not convert image format PixelFormat::I8 to format ID:%d, we will use it's origin format PixelFormat::I8", static_cast(format)); } *outData = (unsigned char*)data; @@ -900,7 +900,7 @@ Texture2D::PixelFormat Texture2D::convertAI88ToFormat(const unsigned char* data, // unsupported conversion or don't need to convert if (format != PixelFormat::AUTO && format != PixelFormat::AI88) { - CCLOG("Can not convert image format PixelFormat::AI88 to format ID:%d, we will use it's origin format PixelFormat::AI88", format); + CCLOG("Can not convert image format PixelFormat::AI88 to format ID:%d, we will use it's origin format PixelFormat::AI88", static_cast(format)); } *outData = (unsigned char*)data; @@ -955,7 +955,7 @@ Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* dat // unsupported conversion or don't need to convert if (format != PixelFormat::AUTO && format != PixelFormat::RGB888) { - CCLOG("Can not convert image format PixelFormat::RGB888 to format ID:%d, we will use it's origin format PixelFormat::RGB888", format); + CCLOG("Can not convert image format PixelFormat::RGB888 to format ID:%d, we will use it's origin format PixelFormat::RGB888", static_cast(format)); } *outData = (unsigned char*)data; @@ -1009,7 +1009,7 @@ Texture2D::PixelFormat Texture2D::convertRGBA8888ToFormat(const unsigned char* d // unsupported conversion or don't need to convert if (format != PixelFormat::AUTO && format != PixelFormat::RGBA8888) { - CCLOG("Can not convert image format PixelFormat::RGBA8888 to format ID:%d, we will use it's origin format PixelFormat::RGBA8888", format); + CCLOG("Can not convert image format PixelFormat::RGBA8888 to format ID:%d, we will use it's origin format PixelFormat::RGBA8888", static_cast(format)); } *outData = (unsigned char*)data; @@ -1058,7 +1058,7 @@ Texture2D::PixelFormat Texture2D::convertDataToFormat(const unsigned char* data, case PixelFormat::RGBA8888: return convertRGBA8888ToFormat(data, dataLen, format, outData, outDataLen); default: - CCLOG("unsupported conversion from format %d to format %d", originFormat, format); + CCLOG("unsupported conversion from format %d to format %d", static_cast(originFormat), static_cast(format)); *outData = (unsigned char*)data; *outDataLen = dataLen; return originFormat; diff --git a/extensions/assets-manager/AssetsManagerEx.cpp b/extensions/assets-manager/AssetsManagerEx.cpp index 364a2bf88c..a78e324de9 100644 --- a/extensions/assets-manager/AssetsManagerEx.cpp +++ b/extensions/assets-manager/AssetsManagerEx.cpp @@ -823,7 +823,7 @@ const DownloadUnits& AssetsManagerEx::getFailedAssets() const void AssetsManagerEx::downloadFailedAssets() { - CCLOG("AssetsManagerEx : Start update %lu failed assets.\n", _failedUnits.size()); + CCLOG("AssetsManagerEx : Start update %lu failed assets.\n", static_cast(_failedUnits.size())); updateAssets(_failedUnits); } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp index f57a12b4a6..93f3f911e2 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp @@ -212,12 +212,12 @@ void Box2DView::onTouchEnded(Touch* touch, Event* event) void Box2DView::onKeyPressed(EventKeyboard::KeyCode code, Event* event) { - log("Box2dView:onKeyPressed, keycode: %d", code); + log("Box2dView:onKeyPressed, keycode: %d", static_cast(code)); m_test->Keyboard(static_cast(code)); } void Box2DView::onKeyReleased(EventKeyboard::KeyCode code, Event* event) { - log("onKeyReleased, keycode: %d", code); + log("onKeyReleased, keycode: %d", static_cast(code)); m_test->KeyboardUp(static_cast(code)); } diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp index 6316cdd988..f8a6f878d4 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp @@ -892,7 +892,7 @@ void CameraCullingDemo::addSpriteCallback(Ref* sender) // update sprite number char szText[16]; - sprintf(szText,"%ld sprits",_layer3D->getChildrenCount()); + sprintf(szText,"%ld sprits", static_cast(_layer3D->getChildrenCount())); _labelSprite3DCount->setString(szText); } @@ -920,7 +920,7 @@ void CameraCullingDemo::delSpriteCallback(Ref* sender) // update sprite number char szText[16]; - sprintf(szText,"%ld sprits",_layer3D->getChildrenCount()); + sprintf(szText,"%ld sprits", static_cast(_layer3D->getChildrenCount())); _labelSprite3DCount->setString(szText); } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp index e5b50557dd..9163c56ce7 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp @@ -181,7 +181,7 @@ bool ControlButtonTest_Event::init() void ControlButtonTest_Event::touchBitmaskAction(Ref *senderz, Control::EventType controlEvent) { - _displayBitmaskLabel->setString(StringUtils::format("using bitmask (%d)", controlEvent)); + _displayBitmaskLabel->setString(StringUtils::format("using bitmask (%d)", static_cast(controlEvent))); } void ControlButtonTest_Event::touchDownAction(Ref *senderz, Control::EventType controlEvent) diff --git a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp index 632785cffc..0d54267090 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp @@ -187,11 +187,11 @@ void WebSocketTest::onClose(network::WebSocket* ws) void WebSocketTest::onError(network::WebSocket* ws, const network::WebSocket::ErrorCode& error) { - log("Error was fired, error code: %d", error); + log("Error was fired, error code: %d", static_cast(error)); if (ws == _wsiError) { char buf[100] = {0}; - sprintf(buf, "an error was fired, code: %d", error); + sprintf(buf, "an error was fired, code: %d", static_cast(error)); _errorStatus->setString(buf); } } @@ -308,6 +308,6 @@ void WebSocketCloseTest::onClose(network::WebSocket* ws) void WebSocketCloseTest::onError(network::WebSocket* ws, const network::WebSocket::ErrorCode& error) { - log("Error was fired, error code: %d", error); + log("Error was fired, error code: %d", static_cast(error)); } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp index 53edbfa6f0..97b7cb027f 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp @@ -47,7 +47,7 @@ bool TableViewTest::init() void TableViewTest::tableCellTouched(TableView* table, TableViewCell* cell) { - CCLOG("cell touched at index: %ld", cell->getIdx()); + CCLOG("cell touched at index: %ld", static_cast(cell->getIdx())); } Size TableViewTest::tableCellSizeForIndex(TableView *table, ssize_t idx) @@ -60,7 +60,7 @@ Size TableViewTest::tableCellSizeForIndex(TableView *table, ssize_t idx) TableViewCell* TableViewTest::tableCellAtIndex(TableView *table, ssize_t idx) { - auto string = StringUtils::format("%ld", idx); + auto string = StringUtils::format("%ld", static_cast(idx)); TableViewCell *cell = table->dequeueCell(); if (!cell) { cell = new (std::nothrow) CustomTableViewCell(); diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index d182278153..0ecbd8f814 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -1490,7 +1490,7 @@ void Sprite3DWithOBBPerformanceTest::onTouchesMoved(const std::vector& t void Sprite3DWithOBBPerformanceTest::update(float dt) { char szText[16]; - sprintf(szText,"%lu cubes",_obb.size()); + sprintf(szText,"%lu cubes", static_cast(_obb.size())); _labelCubeCount->setString(szText); if (_drawDebug) diff --git a/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp b/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp index 5f254ea698..5236272b58 100644 --- a/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp +++ b/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp @@ -263,7 +263,7 @@ void TextureWEBP::onEnter() addChild(img); log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); Texture2D* texture = Director::getInstance()->getTextureCache()->getTextureForKey("Images/test_image.webp"); - log("pixel format:%d, premultiplied alpha:%d\n", texture->getPixelFormat(), texture->hasPremultipliedAlpha()); + log("pixel format:%d, premultiplied alpha:%d\n", static_cast(texture->getPixelFormat()), texture->hasPremultipliedAlpha()); } std::string TextureWEBP::title() const @@ -286,7 +286,7 @@ void TextureWEBPNoAlpha::onEnter() addChild(img); log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); Texture2D* texture = Director::getInstance()->getTextureCache()->getTextureForKey("Images/test_image_no_alpha.webp"); - log("pixel format:%d, premultiplied alpha:%d\n", texture->getPixelFormat(), texture->hasPremultipliedAlpha()); + log("pixel format:%d, premultiplied alpha:%d\n", static_cast(texture->getPixelFormat()), texture->hasPremultipliedAlpha()); } std::string TextureWEBPNoAlpha::title() const diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index f720f680fa..b3899f8836 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -100,7 +100,7 @@ void UIPageViewTest::pageViewEvent(Ref *pSender, PageView::EventType type) { PageView* pageView = dynamic_cast(pSender); - _displayValueLabel->setString(StringUtils::format("page = %ld", pageView->getCurrentPageIndex() + 1)); + _displayValueLabel->setString(StringUtils::format("page = %ld", static_cast(pageView->getCurrentPageIndex() + 1))); } break; @@ -210,7 +210,7 @@ void UIPageViewButtonTest::pageViewEvent(Ref *pSender, PageView::EventType type) { PageView* pageView = dynamic_cast(pSender); - _displayValueLabel->setString(StringUtils::format("page = %ld", pageView->getCurrentPageIndex() + 1)); + _displayValueLabel->setString(StringUtils::format("page = %ld", static_cast(pageView->getCurrentPageIndex() + 1))); } break; @@ -407,7 +407,7 @@ void UIPageViewTouchPropagationTest::pageViewEvent(Ref *pSender, PageView::Event { PageView* pageView = dynamic_cast(pSender); - _displayValueLabel->setString(StringUtils::format("page = %ld", pageView->getCurrentPageIndex() + 1)); + _displayValueLabel->setString(StringUtils::format("page = %ld", static_cast(pageView->getCurrentPageIndex() + 1))); } break; @@ -527,7 +527,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init() } pageView->pushBackCustomItem(outerBox); - _displayValueLabel->setString(StringUtils::format("page count = %ld", pageView->getItems().size())); + _displayValueLabel->setString(StringUtils::format("page count = %ld", static_cast(pageView->getItems().size()))); CCLOG("current page index = %zd", pageView->getCurrentPageIndex()); }); _uiLayer->addChild(button); @@ -548,7 +548,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init() { CCLOG("There is no page to remove!"); } - _displayValueLabel->setString(StringUtils::format("page count = %ld", pageView->getItems().size())); + _displayValueLabel->setString(StringUtils::format("page count = %ld", static_cast(pageView->getItems().size()))); CCLOG("current page index = %zd", pageView->getCurrentPageIndex()); }); @@ -563,7 +563,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init() button3->addClickEventListener([=](Ref* sender) { pageView->removeAllItems(); - _displayValueLabel->setString(StringUtils::format("page count = %ld", pageView->getItems().size())); + _displayValueLabel->setString(StringUtils::format("page count = %ld", static_cast(pageView->getItems().size()))); CCLOG("current page index = %zd", pageView->getCurrentPageIndex()); }); @@ -592,7 +592,7 @@ void UIPageViewDynamicAddAndRemoveTest::pageViewEvent(Ref *pSender, PageView::Ev { PageView* pageView = dynamic_cast(pSender); - _displayValueLabel->setString(StringUtils::format("page = %ld", pageView->getCurrentPageIndex() + 1)); + _displayValueLabel->setString(StringUtils::format("page = %ld", static_cast((pageView->getCurrentPageIndex() + 1)))); } break; @@ -794,7 +794,7 @@ void UIPageViewVerticalTest::pageViewEvent(Ref *pSender, PageView::EventType typ { PageView* pageView = dynamic_cast(pSender); - _displayValueLabel->setString(StringUtils::format("page = %ld", pageView->getCurrentPageIndex() + 1)); + _displayValueLabel->setString(StringUtils::format("page = %ld", static_cast(pageView->getCurrentPageIndex() + 1))); } break; @@ -953,7 +953,7 @@ void UIPageViewChildSizeTest::pageViewEvent(Ref *pSender, PageView::EventType ty { PageView* pageView = dynamic_cast(pSender); - _displayValueLabel->setString(StringUtils::format("page = %ld", pageView->getCurrentPageIndex() + 1)); + _displayValueLabel->setString(StringUtils::format("page = %ld", static_cast(pageView->getCurrentPageIndex() + 1))); } break; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp index 0fdbbe07a9..132887ae3c 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp @@ -39,12 +39,12 @@ bool UIRichTextTest::init() std::string str2 = config->getValue("Japanese").asString(); CCLOG("str1:%s ascii length = %ld, utf8 length = %ld, substr = %s", str1.c_str(), - str1.length(), + static_cast(str1.length()), StringUtils::getCharacterCountInUTF8String(str1), Helper::getSubStringOfUTF8String(str1, 0, 5).c_str()); CCLOG("str2:%s ascii length = %ld, utf8 length = %ld, substr = %s", str2.c_str(), - str2.length(), + static_cast(str2.length()), StringUtils::getCharacterCountInUTF8String(str2), Helper::getSubStringOfUTF8String(str2, 0, 2).c_str());