From 963e1b8b3fdb46b85d813f7439129359d49a8316 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 2 May 2021 12:59:22 +0400 Subject: [PATCH] Fix MSVC's C4244 warnings --- CMakeLists.txt | 2 -- apps/openmw/mwsound/ffmpeg_decoder.hpp | 10 ++++++++++ components/bsa/bsa_file.cpp | 6 +++--- components/compiler/locals.cpp | 2 +- components/compiler/scanner.hpp | 6 +++--- components/esm/statstate.cpp | 7 +++---- components/myguiplatform/scalinglayer.cpp | 12 ++++++------ extern/osg-ffmpeg-videoplayer/audiodecoder.cpp | 13 ++++++++++--- extern/osg-ffmpeg-videoplayer/audiodecoder.hpp | 9 +++++++++ extern/osg-ffmpeg-videoplayer/videostate.cpp | 9 +++++++++ extern/osg-ffmpeg-videoplayer/videostate.hpp | 9 +++++++++ 11 files changed, 63 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe31951df..053f9def1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -603,10 +603,8 @@ if (WIN32) set(WARNINGS "/W4") set(WARNINGS_DISABLE - # OpenMW specific warnings 4100 # Unreferenced formal parameter (-Wunused-parameter) 4127 # Conditional expression is constant - 4244 # Storing value of one type in variable of another (size_t in int, for example) 4996 # Function was declared deprecated ) diff --git a/apps/openmw/mwsound/ffmpeg_decoder.hpp b/apps/openmw/mwsound/ffmpeg_decoder.hpp index f099c831c..0a67a4758 100644 --- a/apps/openmw/mwsound/ffmpeg_decoder.hpp +++ b/apps/openmw/mwsound/ffmpeg_decoder.hpp @@ -2,6 +2,12 @@ #define GAME_SOUND_FFMPEG_DECODER_H #include + +#if defined(_MSC_VER) + #pragma warning (push) + #pragma warning (disable : 4244) +#endif + extern "C" { #include @@ -14,6 +20,10 @@ extern "C" #include } +#if defined(_MSC_VER) + #pragma warning (pop) +#endif + #include #include diff --git a/components/bsa/bsa_file.cpp b/components/bsa/bsa_file.cpp index 4758d0a86..158080ea3 100644 --- a/components/bsa/bsa_file.cpp +++ b/components/bsa/bsa_file.cpp @@ -295,7 +295,7 @@ void Bsa::BSAFile::addFile(const std::string& filename, std::istream& file) FileStruct newFile; file.seekg(0, std::ios::end); - newFile.fileSize = file.tellg(); + newFile.fileSize = static_cast(file.tellg()); newFile.setNameInfos(mStringBuf.size(), &mStringBuf); newFile.hash = getHash(filename); @@ -312,7 +312,7 @@ void Bsa::BSAFile::addFile(const std::string& filename, std::istream& file) stream.read(buffer.data(), firstFile.fileSize); stream.seekp(0, std::ios::end); - firstFile.offset = stream.tellp(); + firstFile.offset = static_cast(stream.tellp()); stream.write(buffer.data(), firstFile.fileSize); @@ -320,7 +320,7 @@ void Bsa::BSAFile::addFile(const std::string& filename, std::istream& file) std::rotate(mFiles.begin(), mFiles.begin() + 1, mFiles.end()); } stream.seekp(0, std::ios::end); - newFile.offset = stream.tellp(); + newFile.offset = static_cast(stream.tellp()); } mStringBuf.insert(mStringBuf.end(), filename.begin(), filename.end()); diff --git a/components/compiler/locals.cpp b/components/compiler/locals.cpp index 9b233b8f5..f31acb1a8 100644 --- a/components/compiler/locals.cpp +++ b/components/compiler/locals.cpp @@ -30,7 +30,7 @@ namespace Compiler if (iter==collection.end()) return -1; - return iter-collection.begin(); + return static_cast(iter-collection.begin()); } bool Locals::search (char type, const std::string& name) const diff --git a/components/compiler/scanner.hpp b/components/compiler/scanner.hpp index 9c7bd656e..fd7de5b6b 100644 --- a/components/compiler/scanner.hpp +++ b/components/compiler/scanner.hpp @@ -103,7 +103,7 @@ namespace Compiler { blank(); - char ch = in.peek(); + char ch = static_cast(in.peek()); if (!in.good()) return false; @@ -130,7 +130,7 @@ namespace Compiler { std::streampos p_orig = in.tellg(); - char ch = in.peek(); + char ch = static_cast(in.peek()); if (!in.good()) return false; @@ -156,7 +156,7 @@ namespace Compiler void blank() { - std::fill(mData, mData + sizeof(mData), 0); + std::fill(std::begin(mData), std::end(mData), '\0'); mLength = -1; } diff --git a/components/esm/statstate.cpp b/components/esm/statstate.cpp index b9ddc3efd..30d39e3c6 100644 --- a/components/esm/statstate.cpp +++ b/components/esm/statstate.cpp @@ -16,17 +16,16 @@ namespace ESM { int base = 0; esm.getHNT(base, "STBA"); - mBase = static_cast(base); + mBase = static_cast(base); int mod = 0; esm.getHNOT(mod, "STMO"); - mMod = static_cast(mod); + mMod = static_cast(mod); int current = 0; esm.getHNOT(current, "STCU"); - mCurrent = static_cast(current); + mCurrent = static_cast(current); - // mDamage was changed to a float; ensure backwards compatibility int oldDamage = 0; esm.getHNOT(oldDamage, "STDA"); mDamage = static_cast(oldDamage); diff --git a/components/myguiplatform/scalinglayer.cpp b/components/myguiplatform/scalinglayer.cpp index 99ed6d07a..51c148253 100644 --- a/components/myguiplatform/scalinglayer.cpp +++ b/components/myguiplatform/scalinglayer.cpp @@ -74,8 +74,8 @@ namespace osgMyGUI _left -= globalViewSize.width/2; _top -= globalViewSize.height/2; - _left /= scale; - _top /= scale; + _left = static_cast(_left/scale); + _top = static_cast(_top/scale); _left += mViewSize.width/2; _top += mViewSize.height/2; @@ -84,8 +84,8 @@ namespace osgMyGUI float ScalingLayer::getScaleFactor() const { MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); - float w = viewSize.width; - float h = viewSize.height; + float w = static_cast(viewSize.width); + float h = static_cast(viewSize.height); float heightScale = (h / mViewSize.height); float widthScale = (w / mViewSize.width); @@ -103,8 +103,8 @@ namespace osgMyGUI MyGUI::IntSize globalViewSize = MyGUI::RenderManager::getInstance().getViewSize(); MyGUI::IntSize viewSize = globalViewSize; float scale = getScaleFactor(); - viewSize.width /= scale; - viewSize.height /= scale; + viewSize.width = static_cast(viewSize.width / scale); + viewSize.height = static_cast(viewSize.height / scale); float hoffset = (globalViewSize.width - mViewSize.width*getScaleFactor())/2.f / static_cast(globalViewSize.width); float voffset = (globalViewSize.height - mViewSize.height*getScaleFactor())/2.f / static_cast(globalViewSize.height); diff --git a/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp b/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp index c78328b2e..b5b3b8a3e 100644 --- a/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp +++ b/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp @@ -4,13 +4,20 @@ #include #include +#if defined(_MSC_VER) + #pragma warning (push) + #pragma warning (disable : 4244) +#endif + extern "C" { - #include - #include } +#if defined(_MSC_VER) + #pragma warning (pop) +#endif + #include "videostate.hpp" namespace @@ -276,7 +283,7 @@ size_t MovieAudioDecoder::read(char *stream, size_t len) mFramePos = std::min(mFrameSize, sample_skip); if(sample_skip > 0 || mFrameSize > -sample_skip) - sample_skip -= mFramePos; + sample_skip -= static_cast(mFramePos); continue; } diff --git a/extern/osg-ffmpeg-videoplayer/audiodecoder.hpp b/extern/osg-ffmpeg-videoplayer/audiodecoder.hpp index afb088431..bbb5a2783 100644 --- a/extern/osg-ffmpeg-videoplayer/audiodecoder.hpp +++ b/extern/osg-ffmpeg-videoplayer/audiodecoder.hpp @@ -6,6 +6,11 @@ #include #include +#if defined(_MSC_VER) + #pragma warning (push) + #pragma warning (disable : 4244) +#endif + extern "C" { #include @@ -14,6 +19,10 @@ extern "C" #include } +#if defined(_MSC_VER) + #pragma warning (pop) +#endif + #if defined(_WIN32) && !defined(__MINGW32__) #include diff --git a/extern/osg-ffmpeg-videoplayer/videostate.cpp b/extern/osg-ffmpeg-videoplayer/videostate.cpp index c153aa14c..a2ea71b19 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.cpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.cpp @@ -9,6 +9,11 @@ #include +#if defined(_MSC_VER) + #pragma warning (push) + #pragma warning (disable : 4244) +#endif + extern "C" { #include @@ -17,6 +22,10 @@ extern "C" #include } +#if defined(_MSC_VER) + #pragma warning (pop) +#endif + static const char* flushString = "FLUSH"; struct FlushPacket : AVPacket { diff --git a/extern/osg-ffmpeg-videoplayer/videostate.hpp b/extern/osg-ffmpeg-videoplayer/videostate.hpp index 015656084..244637b87 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.hpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.hpp @@ -15,6 +15,11 @@ namespace osg class Texture2D; } +#if defined(_MSC_VER) + #pragma warning (push) + #pragma warning (disable : 4244) +#endif + extern "C" { #include @@ -28,6 +33,10 @@ extern "C" #include } +#if defined(_MSC_VER) + #pragma warning (pop) +#endif + #include "videodefs.hpp" #define VIDEO_PICTURE_QUEUE_SIZE 50