From 38316cdaf8b5e8db1a7697a21f5a2ea9f2f6f755 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 17 Apr 2021 19:06:33 +0200 Subject: [PATCH 1/3] Fix various warnings found by clang - unused alias - inefficient use of push_back - exceptions not inheriting from std::exception - weird use of a comma - value compared against itself --- apps/essimporter/main.cpp | 2 +- apps/opencs/model/world/commands.cpp | 1 + apps/opencs/model/world/idtree.cpp | 4 ++-- components/esm/loadregn.cpp | 2 +- components/esm/variantimp.cpp | 7 +------ 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/apps/essimporter/main.cpp b/apps/essimporter/main.cpp index d593669c33..9b969e35af 100644 --- a/apps/essimporter/main.cpp +++ b/apps/essimporter/main.cpp @@ -57,7 +57,7 @@ int main(int argc, char** argv) else { const std::string& ext = ".omwsave"; - if (boost::filesystem::exists(boost::filesystem::path(outputFile)) + if (bfs::exists(bfs::path(outputFile)) && (outputFile.size() < ext.size() || outputFile.substr(outputFile.size()-ext.size()) != ext)) { throw std::runtime_error("Output file already exists and does not end in .omwsave. Did you mean to use --compare?"); diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 34485a46d7..5ec7401dc9 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -76,6 +76,7 @@ void CSMWorld::ImportLandTexturesCommand::redo() } std::vector oldTextures; + oldTextures.reserve(texIndices.size()); for (int index : texIndices) { oldTextures.push_back(LandTexture::createUniqueRecordId(oldPlugin, index)); diff --git a/apps/opencs/model/world/idtree.cpp b/apps/opencs/model/world/idtree.cpp index a8dfacb01d..1e3398bbb2 100644 --- a/apps/opencs/model/world/idtree.cpp +++ b/apps/opencs/model/world/idtree.cpp @@ -201,7 +201,7 @@ QModelIndex CSMWorld::IdTree::parent (const QModelIndex& index) const const std::pair& address(unfoldIndexAddress(id)); if (address.first >= this->rowCount() || address.second >= this->columnCount()) - throw "Parent index is not present in the model"; + throw std::logic_error("Parent index is not present in the model"); return createIndex(address.first, address.second); } @@ -216,7 +216,7 @@ unsigned int CSMWorld::IdTree::foldIndexAddress (const QModelIndex& index) const std::pair< int, int > CSMWorld::IdTree::unfoldIndexAddress (unsigned int id) const { if (id == 0) - throw "Attempt to unfold index id of the top level data cell"; + throw std::runtime_error("Attempt to unfold index id of the top level data cell"); --id; int row = id / this->columnCount(); diff --git a/components/esm/loadregn.cpp b/components/esm/loadregn.cpp index 98edca48f0..a56b9f2474 100644 --- a/components/esm/loadregn.cpp +++ b/components/esm/loadregn.cpp @@ -115,7 +115,7 @@ namespace ESM void Region::blank() { mData.mClear = mData.mCloudy = mData.mFoggy = mData.mOvercast = mData.mRain = - mData.mThunder = mData.mAsh, mData.mBlight = mData.mA = mData.mB = 0; + mData.mThunder = mData.mAsh = mData.mBlight = mData.mA = mData.mB = 0; mMapColor = 0; diff --git a/components/esm/variantimp.cpp b/components/esm/variantimp.cpp index 74d1351ec5..64dc980b8c 100644 --- a/components/esm/variantimp.cpp +++ b/components/esm/variantimp.cpp @@ -52,12 +52,7 @@ void ESM::readESMVariantValue(ESMReader& esm, Variant::Format format, VarType ty esm.getHNT (value, "FLTV"); if (type==VT_Short) - { - if (value!=value) - out = 0; // nan - else - out = static_cast (value); - } + out = static_cast (value); else if (type==VT_Long) out = static_cast (value); else From c0f7e0d5859ebff742630925b0dec15d73991826 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 17 Apr 2021 20:58:09 +0200 Subject: [PATCH 2/3] Use isnan --- components/esm/variantimp.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/esm/variantimp.cpp b/components/esm/variantimp.cpp index 64dc980b8c..129b6c6d0e 100644 --- a/components/esm/variantimp.cpp +++ b/components/esm/variantimp.cpp @@ -52,7 +52,10 @@ void ESM::readESMVariantValue(ESMReader& esm, Variant::Format format, VarType ty esm.getHNT (value, "FLTV"); if (type==VT_Short) - out = static_cast (value); + if (isnan(value)) + out = 0; + else + out = static_cast (value); else if (type==VT_Long) out = static_cast (value); else From 032ba1e9a09473078a010ac948a6d7f43deccfc0 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 18 Apr 2021 13:26:26 +0200 Subject: [PATCH 3/3] Fix the compilation --- components/esm/variantimp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/esm/variantimp.cpp b/components/esm/variantimp.cpp index 129b6c6d0e..b9cd9a8536 100644 --- a/components/esm/variantimp.cpp +++ b/components/esm/variantimp.cpp @@ -1,6 +1,7 @@ #include "variantimp.hpp" #include +#include #include "esmreader.hpp" #include "esmwriter.hpp" @@ -52,7 +53,7 @@ void ESM::readESMVariantValue(ESMReader& esm, Variant::Format format, VarType ty esm.getHNT (value, "FLTV"); if (type==VT_Short) - if (isnan(value)) + if (std::isnan(value)) out = 0; else out = static_cast (value);