From 08985bf68a953fb07601fd1f638ec13fb8fec311 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Thu, 15 Jan 2015 18:52:11 +0100 Subject: [PATCH] Throw exception in getVariableFromVarId() if called with out_of_range varId That way we have a chance to catch code bugs at all. --- lib/symboldatabase.h | 5 +---- test/testsymboldatabase.cpp | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 377adf264..0e5e5c817 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -968,10 +968,7 @@ public: } const Variable *getVariableFromVarId(std::size_t varId) const { - if (varId >= _variableList.size()) - return nullptr; - - return _variableList[varId]; + return _variableList.at(varId); } std::size_t getVariableListSize() const { diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 3771b863a..46fb7716a 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -20,6 +20,7 @@ #include "testutils.h" #include "symboldatabase.h" #include +#include #define GET_SYMBOL_DB(code) \ errout.str(""); \ @@ -759,8 +760,7 @@ private: // three elements: varId 0 also counts via a fake-entry ASSERT(v && db->getVariableListSize() == 3); - const Variable* v_must_be_null = db->getVariableFromVarId(3); - ASSERT(v_must_be_null == nullptr); + ASSERT_THROW(db->getVariableFromVarId(3), std::out_of_range); } void hasRegularFunction() {