From 7fb985d5734a969f098bad8183c633877b9d0cdd Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 16 Jul 2018 10:58:14 +0200 Subject: [PATCH] Bug fix/fix codescan issues (#5872) --- arangod/Aql/ClusterBlocks.cpp | 3 ++- arangod/Aql/ExecutionBlock.cpp | 1 - arangod/Aql/ExecutionEngine.cpp | 2 +- arangod/Aql/Functions.cpp | 16 +++++++--------- arangod/IResearch/IResearchFeature.cpp | 8 ++++---- arangod/IResearch/IResearchFilterFactory.cpp | 15 +++------------ arangod/IResearch/IResearchViewMeta.cpp | 4 ++-- arangod/IResearch/IResearchViewMeta.h | 4 ++-- arangod/Indexes/Index.cpp | 1 - arangod/RocksDBEngine/RocksDBKey.cpp | 12 ++++++------ 10 files changed, 27 insertions(+), 39 deletions(-) diff --git a/arangod/Aql/ClusterBlocks.cpp b/arangod/Aql/ClusterBlocks.cpp index 716f993d44..d67a4626cb 100644 --- a/arangod/Aql/ClusterBlocks.cpp +++ b/arangod/Aql/ClusterBlocks.cpp @@ -198,7 +198,8 @@ class MinElementSorting final : public SortingStrategy, public OurLessThan { arangodb::transaction::Methods* trx, std::vector>& gatherBlockBuffer, std::vector& sortRegisters) noexcept - : OurLessThan(trx, gatherBlockBuffer, sortRegisters) { + : OurLessThan(trx, gatherBlockBuffer, sortRegisters), + _blockPos(nullptr) { } virtual ValueType nextValue() override { diff --git a/arangod/Aql/ExecutionBlock.cpp b/arangod/Aql/ExecutionBlock.cpp index da00011515..15eeffd2f7 100644 --- a/arangod/Aql/ExecutionBlock.cpp +++ b/arangod/Aql/ExecutionBlock.cpp @@ -702,7 +702,6 @@ std::string ExecutionBlock::typeToString(ExecutionBlock::Type type) { // to please compiler in non-maintainer mode THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, std::string("when converting ExecutionBlock::Type to string: got invalid type")); - return ""; } return got->second; } diff --git a/arangod/Aql/ExecutionEngine.cpp b/arangod/Aql/ExecutionEngine.cpp index 02d7a943a4..a369cab9ee 100644 --- a/arangod/Aql/ExecutionEngine.cpp +++ b/arangod/Aql/ExecutionEngine.cpp @@ -586,7 +586,7 @@ ExecutionEngine* ExecutionEngine::instantiateFromPlan( // in short: this avoids copying the return values engine->resultRegister( - dynamic_cast(root)->returnInheritedResults()); + static_cast(root)->returnInheritedResults()); } engine->_root = root; diff --git a/arangod/Aql/Functions.cpp b/arangod/Aql/Functions.cpp index b1162f8b99..fab02626f8 100644 --- a/arangod/Aql/Functions.cpp +++ b/arangod/Aql/Functions.cpp @@ -281,6 +281,9 @@ std::vector> const sortedDateMap = { wrk.append(std::to_string(abs(yearnum))); return; } + + TRI_ASSERT(yearnum >= 0); + if (yearnum > 99999) { // intentionally nothing } else if (yearnum > 9999) { @@ -291,10 +294,8 @@ std::vector> const sortedDateMap = { wrk.append("+000"); } else if (yearnum > 9) { wrk.append("+0000"); - } else if (yearnum >= 0) { - wrk.append("+00000"); } else { - wrk.append("+"); + wrk.append("+00000"); } wrk.append(std::to_string(yearnum)); }}, @@ -316,12 +317,9 @@ std::vector> const sortedDateMap = { wrk.append("-"); } wrk.append(std::to_string(abs(yearnum))); - } - else { - if (yearnum < 0) { - wrk.append("0000"); - wrk.append(std::to_string(yearnum)); - } else if (yearnum < 9) { + } else { + TRI_ASSERT(yearnum >= 0); + if (yearnum < 9) { wrk.append("000"); wrk.append(std::to_string(yearnum)); } else if (yearnum < 99) { diff --git a/arangod/IResearch/IResearchFeature.cpp b/arangod/IResearch/IResearchFeature.cpp index fa723264cc..95e8ae3592 100644 --- a/arangod/IResearch/IResearchFeature.cpp +++ b/arangod/IResearch/IResearchFeature.cpp @@ -426,10 +426,10 @@ class IResearchFeature::Async { mutable bool _wasNotified; // a notification was raised from another thread Thread(std::string const& name) - : arangodb::Thread(name), _wasNotified(false) { + : arangodb::Thread(name), _terminate(nullptr), _wasNotified(false) { } Thread(Thread&& other) // used in constructor before tasks are started - : arangodb::Thread(other.name()), _wasNotified(false) { + : arangodb::Thread(other.name()), _terminate(nullptr), _wasNotified(false) { } virtual bool isSystem() override { return true; } // or start(...) will fail virtual void run() override; @@ -580,7 +580,7 @@ IResearchFeature::Async::Async(): _terminate(false) { auto* last = &(_pool.back()); - // buld circular list + // build circular list for (auto& thread: _pool) { last->_next = &thread; last = &thread; @@ -745,4 +745,4 @@ NS_END // arangodb // ----------------------------------------------------------------------------- // --SECTION-- END-OF-FILE -// ----------------------------------------------------------------------------- \ No newline at end of file +// ----------------------------------------------------------------------------- diff --git a/arangod/IResearch/IResearchFilterFactory.cpp b/arangod/IResearch/IResearchFilterFactory.cpp index dde0c43bbc..961b17c6c3 100644 --- a/arangod/IResearch/IResearchFilterFactory.cpp +++ b/arangod/IResearch/IResearchFilterFactory.cpp @@ -324,6 +324,7 @@ bool byRange( return false; } + TRI_ASSERT(filter); auto& range = filter->add(); kludge::mangleNumeric(name); @@ -1161,6 +1162,7 @@ bool fromFuncAnalyzer( if (!expressionArg) { LOG_TOPIC(WARN, arangodb::iresearch::TOPIC) << "'ANALYZER' AQL function: 1st argument is invalid"; + return false; } // 2nd argument defines a boost @@ -1352,6 +1354,7 @@ bool fromFuncExists( if (!typeArg) { LOG_TOPIC(WARN, arangodb::iresearch::TOPIC) << "'EXISTS' AQL function: 2nd argument is invalid"; + return false; } irs::string_ref arg; @@ -2051,18 +2054,6 @@ bool filter( default: return fromExpression(filter, queryCtx, filterCtx, node); } - - auto const* typeName = arangodb::iresearch::getNodeTypeName(node.type); - - if (typeName) { - LOG_TOPIC(WARN, arangodb::iresearch::TOPIC) - << "Unable to process Ast node of type '" << *typeName << "'"; - } else { - LOG_TOPIC(WARN, arangodb::iresearch::TOPIC) - << "Unable to process Ast node of type '" << node.type << "'"; - } - - return false; // unsupported node type } } diff --git a/arangod/IResearch/IResearchViewMeta.cpp b/arangod/IResearch/IResearchViewMeta.cpp index c04cdb23c5..e6113ade1d 100644 --- a/arangod/IResearch/IResearchViewMeta.cpp +++ b/arangod/IResearch/IResearchViewMeta.cpp @@ -646,7 +646,7 @@ bool IResearchViewMetaState::init( std::string& errorField, IResearchViewMetaState const& defaults /*= DEFAULT()*/, Mask* mask /*= nullptr*/ -) noexcept { +) { if (!slice.isObject()) { errorField = "not an object"; return false; @@ -741,4 +741,4 @@ NS_END // arangodb // ----------------------------------------------------------------------------- // --SECTION-- END-OF-FILE -// ----------------------------------------------------------------------------- \ No newline at end of file +// ----------------------------------------------------------------------------- diff --git a/arangod/IResearch/IResearchViewMeta.h b/arangod/IResearch/IResearchViewMeta.h index ce992c3474..11f2ab7a69 100644 --- a/arangod/IResearch/IResearchViewMeta.h +++ b/arangod/IResearch/IResearchViewMeta.h @@ -222,7 +222,7 @@ struct IResearchViewMetaState { std::string& errorField, IResearchViewMetaState const& defaults = DEFAULT(), Mask* mask = nullptr - ) noexcept; + ); //////////////////////////////////////////////////////////////////////////////// /// @brief fill and return a JSON description of a IResearchViewMeta object @@ -258,4 +258,4 @@ struct IResearchViewMetaState { NS_END // iresearch NS_END // arangodb -#endif \ No newline at end of file +#endif diff --git a/arangod/Indexes/Index.cpp b/arangod/Indexes/Index.cpp index f803fe8317..b59ba95f73 100644 --- a/arangod/Indexes/Index.cpp +++ b/arangod/Indexes/Index.cpp @@ -611,7 +611,6 @@ double Index::selectivityEstimate(StringRef const* extra) const { return 1.0; } THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED); - return 0; } /// @brief default implementation for implicitlyUnique diff --git a/arangod/RocksDBEngine/RocksDBKey.cpp b/arangod/RocksDBEngine/RocksDBKey.cpp index 4d16a2c73d..b918fee8ec 100644 --- a/arangod/RocksDBEngine/RocksDBKey.cpp +++ b/arangod/RocksDBEngine/RocksDBKey.cpp @@ -297,8 +297,9 @@ LocalDocumentId RocksDBKey::documentId(rocksdb::Slice const& slice) { LocalDocumentId RocksDBKey::indexDocumentId(RocksDBEntryType type, rocksdb::Slice const& slice) { - const char* data = slice.data(); - const size_t size = slice.size(); + char const* data = slice.data(); + size_t const size = slice.size(); + switch (type) { case RocksDBEntryType::VPackIndexValue: case RocksDBEntryType::FulltextIndexValue: @@ -314,12 +315,11 @@ LocalDocumentId RocksDBKey::indexDocumentId(RocksDBEntryType type, return LocalDocumentId(uint64FromPersistent(data + size - sizeof(uint64_t) - sizeof(char))); } - default: - THROW_ARANGO_EXCEPTION(TRI_ERROR_TYPE_ERROR); + default: { + } } - - return documentId(type, slice.data(), slice.size()); + THROW_ARANGO_EXCEPTION(TRI_ERROR_TYPE_ERROR); } arangodb::StringRef RocksDBKey::primaryKey(RocksDBKey const& key) {