Throw exception in getVariableFromVarId() if called with out_of_range varId
That way we have a chance to catch code bugs at all.
This commit is contained in:
parent
20aea9deb3
commit
08985bf68a
|
@ -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 {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "testutils.h"
|
||||
#include "symboldatabase.h"
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#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() {
|
||||
|
|
Loading…
Reference in New Issue