From f9d42ed3960430ab0d2c605caafb94a28ee77948 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 2 May 2021 10:43:44 +0400 Subject: [PATCH 1/2] Fix MSVC's C4267 warnings --- CMakeLists.txt | 1 - apps/mwiniimporter/importer.cpp | 10 +++++----- apps/opencs/model/doc/blacklist.cpp | 2 +- apps/opencs/model/filter/narynode.cpp | 2 +- apps/opencs/model/tools/mandatoryid.cpp | 2 +- apps/opencs/model/tools/reportmodel.cpp | 6 +++--- apps/opencs/model/world/idtable.cpp | 2 +- apps/opencs/model/world/resources.cpp | 6 +++--- apps/opencs/view/doc/operations.cpp | 4 ++-- apps/opencs/view/widget/scenetoolrun.cpp | 2 +- apps/opencs/view/widget/scenetooltoggle.cpp | 4 ++-- apps/opencs/view/widget/scenetooltoggle2.cpp | 2 +- apps/opencs/view/world/idvalidator.cpp | 2 +- components/bsa/bsa_file.cpp | 16 ++++++++-------- components/bsa/bsa_file.hpp | 4 ++-- components/compiler/controlparser.cpp | 6 +++--- components/compiler/literals.cpp | 8 ++++---- components/crashcatcher/windows_crashcatcher.cpp | 4 ++-- components/esm/esmreader.cpp | 6 +++--- components/esm/esmwriter.cpp | 2 +- components/files/lowlevelfile.cpp | 4 ++-- components/interpreter/runtime.cpp | 2 +- components/widgets/list.cpp | 2 +- extern/osg-ffmpeg-videoplayer/audiodecoder.cpp | 2 +- 24 files changed, 50 insertions(+), 51 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 104140107..fe31951df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -607,7 +607,6 @@ if (WIN32) 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) - 4267 # Conversion from 'size_t' to 'int', possible loss of data 4996 # Function was declared deprecated ) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 94b5cf7d0..2763d8ad9 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -676,7 +676,7 @@ MwIniImporter::multistrmap MwIniImporter::loadIniFile(const boost::filesystem::p } if(line[0] == '[') { - int pos = line.find(']'); + int pos = static_cast(line.find(']')); if(pos < 2) { std::cout << "Warning: ini file wrongly formatted (" << line << "). Line ignored." << std::endl; continue; @@ -686,12 +686,12 @@ MwIniImporter::multistrmap MwIniImporter::loadIniFile(const boost::filesystem::p continue; } - int comment_pos = line.find(';'); + int comment_pos = static_cast(line.find(';')); if(comment_pos > 0) { line = line.substr(0,comment_pos); } - int pos = line.find('='); + int pos = static_cast(line.find('=')); if(pos < 1) { continue; } @@ -722,7 +722,7 @@ MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const boost::filesystem::p while (std::getline(file, line)) { // we cant say comment by only looking at first char anymore - int comment_pos = line.find('#'); + int comment_pos = static_cast(line.find('#')); if(comment_pos > 0) { line = line.substr(0,comment_pos); } @@ -731,7 +731,7 @@ MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const boost::filesystem::p continue; } - int pos = line.find('='); + int pos = static_cast(line.find('=')); if(pos < 1) { continue; } diff --git a/apps/opencs/model/doc/blacklist.cpp b/apps/opencs/model/doc/blacklist.cpp index b1d402c69..690d79983 100644 --- a/apps/opencs/model/doc/blacklist.cpp +++ b/apps/opencs/model/doc/blacklist.cpp @@ -21,7 +21,7 @@ void CSMDoc::Blacklist::add (CSMWorld::UniversalId::Type type, { std::vector& list = mIds[type]; - int size = list.size(); + size_t size = list.size(); list.resize (size+ids.size()); diff --git a/apps/opencs/model/filter/narynode.cpp b/apps/opencs/model/filter/narynode.cpp index 2fa9ac6cc..9415f1daf 100644 --- a/apps/opencs/model/filter/narynode.cpp +++ b/apps/opencs/model/filter/narynode.cpp @@ -9,7 +9,7 @@ CSMFilter::NAryNode::NAryNode (const std::vector >& nodes, int CSMFilter::NAryNode::getSize() const { - return mNodes.size(); + return static_cast(mNodes.size()); } const CSMFilter::Node& CSMFilter::NAryNode::operator[] (int index) const diff --git a/apps/opencs/model/tools/mandatoryid.cpp b/apps/opencs/model/tools/mandatoryid.cpp index 23adb9d37..d0d9cc0b9 100644 --- a/apps/opencs/model/tools/mandatoryid.cpp +++ b/apps/opencs/model/tools/mandatoryid.cpp @@ -11,7 +11,7 @@ CSMTools::MandatoryIdStage::MandatoryIdStage (const CSMWorld::CollectionBase& id int CSMTools::MandatoryIdStage::setup() { - return mIds.size(); + return static_cast(mIds.size()); } void CSMTools::MandatoryIdStage::perform (int stage, CSMDoc::Messages& messages) diff --git a/apps/opencs/model/tools/reportmodel.cpp b/apps/opencs/model/tools/reportmodel.cpp index f9a1fdb0c..a2901a663 100644 --- a/apps/opencs/model/tools/reportmodel.cpp +++ b/apps/opencs/model/tools/reportmodel.cpp @@ -24,7 +24,7 @@ int CSMTools::ReportModel::rowCount (const QModelIndex & parent) const if (parent.isValid()) return 0; - return mRows.size(); + return static_cast(mRows.size()); } int CSMTools::ReportModel::columnCount (const QModelIndex & parent) const @@ -140,7 +140,7 @@ bool CSMTools::ReportModel::removeRows (int row, int count, const QModelIndex& p void CSMTools::ReportModel::add (const CSMDoc::Message& message) { - beginInsertRows (QModelIndex(), mRows.size(), mRows.size()); + beginInsertRows (QModelIndex(), static_cast(mRows.size()), static_cast(mRows.size())); mRows.push_back (message); @@ -176,7 +176,7 @@ void CSMTools::ReportModel::clear() { if (!mRows.empty()) { - beginRemoveRows (QModelIndex(), 0, mRows.size()-1); + beginRemoveRows (QModelIndex(), 0, static_cast(mRows.size())-1); mRows.clear(); endRemoveRows(); } diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index 27d60ae98..30fe6f639 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -270,7 +270,7 @@ void CSMWorld::IdTable::reorderRows (int baseIndex, const std::vector& newO if (!newOrder.empty()) if (mIdCollection->reorderRows (baseIndex, newOrder)) emit dataChanged (index (baseIndex, 0), - index (baseIndex+newOrder.size()-1, mIdCollection->getColumns()-1)); + index (baseIndex+static_cast(newOrder.size())-1, mIdCollection->getColumns()-1)); } std::pair CSMWorld::IdTable::view (int row) const diff --git a/apps/opencs/model/world/resources.cpp b/apps/opencs/model/world/resources.cpp index b40ab1389..c3eb9762e 100644 --- a/apps/opencs/model/world/resources.cpp +++ b/apps/opencs/model/world/resources.cpp @@ -20,13 +20,13 @@ void CSMWorld::Resources::recreate(const VFS::Manager* vfs, const char * const * mFiles.clear(); mIndex.clear(); - int baseSize = mBaseDirectory.size(); + size_t baseSize = mBaseDirectory.size(); const std::map& index = vfs->getIndex(); for (std::map::const_iterator it = index.begin(); it != index.end(); ++it) { std::string filepath = it->first; - if (static_cast (filepath.size())(mFiles.size()); } std::string CSMWorld::Resources::getId (int index) const diff --git a/apps/opencs/view/doc/operations.cpp b/apps/opencs/view/doc/operations.cpp index 7ee4b8726..9ed77ff9c 100644 --- a/apps/opencs/view/doc/operations.cpp +++ b/apps/opencs/view/doc/operations.cpp @@ -30,7 +30,7 @@ void CSVDoc::Operations::setProgress (int current, int max, int type, int thread return; } - int oldCount = mOperations.size(); + int oldCount = static_cast(mOperations.size()); int newCount = oldCount + 1; Operation *operation = new Operation (type, this); @@ -51,7 +51,7 @@ void CSVDoc::Operations::quitOperation (int type) for (std::vector::iterator iter (mOperations.begin()); iter!=mOperations.end(); ++iter) if ((*iter)->getType()==type) { - int oldCount = mOperations.size(); + int oldCount = static_cast(mOperations.size()); int newCount = oldCount - 1; mLayout->removeItem ((*iter)->getLayout()); diff --git a/apps/opencs/view/widget/scenetoolrun.cpp b/apps/opencs/view/widget/scenetoolrun.cpp index b53282036..24bcf3f13 100644 --- a/apps/opencs/view/widget/scenetoolrun.cpp +++ b/apps/opencs/view/widget/scenetoolrun.cpp @@ -30,7 +30,7 @@ void CSVWidget::SceneToolRun::updateIcon() void CSVWidget::SceneToolRun::updatePanel() { - mTable->setRowCount (mProfiles.size()); + mTable->setRowCount (static_cast(mProfiles.size())); int i = 0; diff --git a/apps/opencs/view/widget/scenetooltoggle.cpp b/apps/opencs/view/widget/scenetooltoggle.cpp index fa0be3155..04ac3322b 100644 --- a/apps/opencs/view/widget/scenetooltoggle.cpp +++ b/apps/opencs/view/widget/scenetooltoggle.cpp @@ -80,7 +80,7 @@ QRect CSVWidget::SceneToolToggle::getIconBox (int index) const int y = index / xMax; int x = index % xMax; - int total = mButtons.size(); + int total = static_cast(mButtons.size()); int actualYIcons = total/xMax; @@ -154,7 +154,7 @@ void CSVWidget::SceneToolToggle::addButton (const std::string& icon, unsigned in desc.mMask = mask; desc.mSmallIcon = smallIcon; desc.mName = name; - desc.mIndex = mButtons.size(); + desc.mIndex = static_cast(mButtons.size()); mButtons.insert (std::make_pair (button, desc)); diff --git a/apps/opencs/view/widget/scenetooltoggle2.cpp b/apps/opencs/view/widget/scenetooltoggle2.cpp index cf9bfe349..363cae570 100644 --- a/apps/opencs/view/widget/scenetooltoggle2.cpp +++ b/apps/opencs/view/widget/scenetooltoggle2.cpp @@ -99,7 +99,7 @@ void CSVWidget::SceneToolToggle2::addButton (unsigned int id, unsigned int mask, desc.mButtonId = id; desc.mMask = mask; desc.mName = name; - desc.mIndex = mButtons.size(); + desc.mIndex = static_cast(mButtons.size()); mButtons.insert (std::make_pair (button, desc)); diff --git a/apps/opencs/view/world/idvalidator.cpp b/apps/opencs/view/world/idvalidator.cpp index 1092d7217..442157ac5 100644 --- a/apps/opencs/view/world/idvalidator.cpp +++ b/apps/opencs/view/world/idvalidator.cpp @@ -42,7 +42,7 @@ QValidator::State CSVWorld::IdValidator::validate (QString& input, int& pos) con if (!mNamespace.empty()) { - std::string namespace_ = input.left (mNamespace.size()).toUtf8().constData(); + std::string namespace_ = input.left (static_cast(mNamespace.size())).toUtf8().constData(); if (Misc::StringUtils::lowerCase (namespace_)!=mNamespace) return QValidator::Invalid; // incorrect namespace diff --git a/components/bsa/bsa_file.cpp b/components/bsa/bsa_file.cpp index ec455ea1f..4758d0a86 100644 --- a/components/bsa/bsa_file.cpp +++ b/components/bsa/bsa_file.cpp @@ -43,7 +43,7 @@ void BSAFile::fail(const std::string &msg) BSAFile::Hash getHash(const std::string& name) { BSAFile::Hash hash; - unsigned l = (name.size() >> 1); + unsigned l = (static_cast(name.size()) >> 1); unsigned sum, off, temp, i, n; for (sum = off = i = 0; i < l; i++) { @@ -163,7 +163,7 @@ void BSAFile::readHeader() { FileStruct &fs = mFiles[i]; fs.fileSize = offsets[i*2]; - fs.offset = offsets[i*2+1] + fileDataOffset; + fs.offset = static_cast(offsets[i*2+1] + fileDataOffset); auto namesOffset = offsets[2*filenum+i]; fs.setNameInfos(namesOffset, &mStringBuf); fs.hash = hashes[i]; @@ -203,11 +203,11 @@ void Bsa::BSAFile::writeHeader() uint32_t head[3]; head[0] = 0x100; auto fileDataOffset = mFiles.empty() ? 12 : mFiles.front().offset; - head[1] = fileDataOffset - 12 - 8*mFiles.size(); + head[1] = static_cast(fileDataOffset - 12 - 8*mFiles.size()); output.seekp(0, std::ios_base::end); - head[2] = mFiles.size(); + head[2] = static_cast(mFiles.size()); output.seekp(0); output.write(reinterpret_cast(head), 12); @@ -239,9 +239,9 @@ int BSAFile::getIndex(const char *str) const if(it == mLookup.end()) return -1; - int res = it->second; - assert(res >= 0 && (size_t)res < mFiles.size()); - return res; + size_t res = it->second; + assert(res >= 0 && res < mFiles.size()); + return static_cast(res); } /// Open an archive file. @@ -300,7 +300,7 @@ void Bsa::BSAFile::addFile(const std::string& filename, std::istream& file) newFile.hash = getHash(filename); if(mFiles.empty()) - newFile.offset = newStartOfDataBuffer; + newFile.offset = static_cast(newStartOfDataBuffer); else { std::vector buffer; diff --git a/components/bsa/bsa_file.hpp b/components/bsa/bsa_file.hpp index fa6e5fc1c..f9b4d4fa3 100644 --- a/components/bsa/bsa_file.hpp +++ b/components/bsa/bsa_file.hpp @@ -58,7 +58,7 @@ public: void setNameInfos(size_t index, std::vector* stringBuf ) { - namesOffset = index; + namesOffset = static_cast(index); namesBuffer = stringBuf; } @@ -102,7 +102,7 @@ protected: the files[] vector above. The iltstr ensures that file name checks are case insensitive. */ - typedef std::map Lookup; + typedef std::map Lookup; Lookup mLookup; /// Error handling diff --git a/components/compiler/controlparser.cpp b/components/compiler/controlparser.cpp index ec69fffa2..a5a68edbd 100644 --- a/components/compiler/controlparser.cpp +++ b/components/compiler/controlparser.cpp @@ -39,14 +39,14 @@ namespace Compiler Codes block; if (iter!=mIfCode.rbegin()) - Generator::jump (iter->second, codes.size()+1); + Generator::jump (iter->second, static_cast(codes.size()+1)); if (!iter->first.empty()) { // if or elseif std::copy (iter->first.begin(), iter->first.end(), std::back_inserter (block)); - Generator::jumpOnZero (block, iter->second.size()+1); + Generator::jumpOnZero (block, static_cast(iter->second.size()+1)); } std::copy (iter->second.begin(), iter->second.end(), @@ -113,7 +113,7 @@ namespace Compiler Codes skip; - Generator::jumpOnZero (skip, mCodeBlock.size()+loop.size()+1); + Generator::jumpOnZero (skip, static_cast (mCodeBlock.size()+loop.size()+1)); std::copy (skip.begin(), skip.end(), std::back_inserter (mCode)); diff --git a/components/compiler/literals.cpp b/components/compiler/literals.cpp index 774ca4ca7..a40ff2a02 100644 --- a/components/compiler/literals.cpp +++ b/components/compiler/literals.cpp @@ -6,12 +6,12 @@ namespace Compiler { int Literals::getIntegerSize() const { - return mIntegers.size() * sizeof (Interpreter::Type_Integer); + return static_cast(mIntegers.size() * sizeof (Interpreter::Type_Integer)); } int Literals::getFloatSize() const { - return mFloats.size() * sizeof (Interpreter::Type_Float); + return static_cast(mFloats.size() * sizeof (Interpreter::Type_Float)); } int Literals::getStringSize() const @@ -41,11 +41,11 @@ namespace Compiler code.resize (size+stringBlockSize/4); - int offset = 0; + size_t offset = 0; for (const auto & mString : mStrings) { - int stringSize = mString.size()+1; + size_t stringSize = mString.size()+1; std::copy (mString.c_str(), mString.c_str()+stringSize, reinterpret_cast (&code[size]) + offset); diff --git a/components/crashcatcher/windows_crashcatcher.cpp b/components/crashcatcher/windows_crashcatcher.cpp index 185eee6aa..39ac86d7b 100644 --- a/components/crashcatcher/windows_crashcatcher.cpp +++ b/components/crashcatcher/windows_crashcatcher.cpp @@ -130,12 +130,12 @@ namespace Crash DWORD copied = 0; do { executablePath.resize(executablePath.size() + MAX_PATH); - copied = GetModuleFileNameW(nullptr, executablePath.data(), executablePath.size()); + copied = GetModuleFileNameW(nullptr, executablePath.data(), static_cast(executablePath.size())); } while (copied >= executablePath.size()); executablePath.resize(copied); memset(mShm->mStartup.mLogFilePath, 0, sizeof(mShm->mStartup.mLogFilePath)); - int length = crashLogPath.length(); + size_t length = crashLogPath.length(); if (length >= MAX_LONG_PATH) length = MAX_LONG_PATH - 1; strncpy(mShm->mStartup.mLogFilePath, crashLogPath.c_str(), length); mShm->mStartup.mLogFilePath[length] = '\0'; diff --git a/components/esm/esmreader.cpp b/components/esm/esmreader.cpp index 30c38d739..b779d7f7f 100644 --- a/components/esm/esmreader.cpp +++ b/components/esm/esmreader.cpp @@ -203,9 +203,9 @@ void ESMReader::getSubName() } // reading the subrecord data anyway. - const size_t subNameSize = mCtx.subName.data_size(); + const int subNameSize = static_cast(mCtx.subName.data_size()); getExact(mCtx.subName.rw_data(), subNameSize); - mCtx.leftRec -= subNameSize; + mCtx.leftRec -= static_cast(subNameSize); } void ESMReader::skipHSub() @@ -327,7 +327,7 @@ std::string ESMReader::getString(int size) char *ptr = mBuffer.data(); getExact(ptr, size); - size = strnlen(ptr, size); + size = static_cast(strnlen(ptr, size)); // Convert to UTF8 and return if (mEncoder) diff --git a/components/esm/esmwriter.cpp b/components/esm/esmwriter.cpp index 09fca4b26..f65340f70 100644 --- a/components/esm/esmwriter.cpp +++ b/components/esm/esmwriter.cpp @@ -217,7 +217,7 @@ namespace ESM if (mCounting && !mRecords.empty()) { for (std::list::iterator it = mRecords.begin(); it != mRecords.end(); ++it) - it->size += size; + it->size += static_cast(size); } mStream->write(data, size); diff --git a/components/files/lowlevelfile.cpp b/components/files/lowlevelfile.cpp index 07915abba..d89ae5838 100644 --- a/components/files/lowlevelfile.cpp +++ b/components/files/lowlevelfile.cpp @@ -326,7 +326,7 @@ void LowLevelFile::seek (size_t position) { assert (mHandle != INVALID_HANDLE_VALUE); - if (SetFilePointer (mHandle, position, nullptr, SEEK_SET) == INVALID_SET_FILE_POINTER) + if (SetFilePointer (mHandle, static_cast(position), nullptr, SEEK_SET) == INVALID_SET_FILE_POINTER) if (GetLastError () != NO_ERROR) throw std::runtime_error ("A seek operation on a file failed."); } @@ -349,7 +349,7 @@ size_t LowLevelFile::read (void * data, size_t size) DWORD read; - if (!ReadFile (mHandle, data, size, &read, nullptr)) + if (!ReadFile (mHandle, data, static_cast(size), &read, nullptr)) throw std::runtime_error ("A read operation on a file failed."); return read; diff --git a/components/interpreter/runtime.cpp b/components/interpreter/runtime.cpp index 35ad93a8a..1cb8f558c 100644 --- a/components/interpreter/runtime.cpp +++ b/components/interpreter/runtime.cpp @@ -45,7 +45,7 @@ namespace Interpreter for (; index; --index) { - offset += std::strlen (literalBlock+offset) + 1; + offset += static_cast(std::strlen (literalBlock+offset)) + 1; if (offset / 4 >= static_cast (mCode[3])) throw std::out_of_range("out of range"); } diff --git a/components/widgets/list.cpp b/components/widgets/list.cpp index 73ca94929..e961b04cb 100644 --- a/components/widgets/list.cpp +++ b/components/widgets/list.cpp @@ -115,7 +115,7 @@ namespace Gui unsigned int MWList::getItemCount() { - return mItems.size(); + return static_cast(mItems.size()); } std::string MWList::getItemNameAt(unsigned int at) diff --git a/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp b/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp index c32794d2a..c78328b2e 100644 --- a/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp +++ b/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp @@ -255,7 +255,7 @@ size_t MovieAudioDecoder::read(char *stream, size_t len) size_t sampleSize = av_get_bytes_per_sample(mOutputSampleFormat); char* data[1]; data[0] = stream; - av_samples_set_silence((uint8_t**)data, 0, len/sampleSize, 1, mOutputSampleFormat); + av_samples_set_silence((uint8_t**)data, 0, static_cast(len/sampleSize), 1, mOutputSampleFormat); return len; } From 963e1b8b3fdb46b85d813f7439129359d49a8316 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 2 May 2021 12:59:22 +0400 Subject: [PATCH 2/2] 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