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 {
|
const Variable *getVariableFromVarId(std::size_t varId) const {
|
||||||
if (varId >= _variableList.size())
|
return _variableList.at(varId);
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return _variableList[varId];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t getVariableListSize() const {
|
std::size_t getVariableListSize() const {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
#include "symboldatabase.h"
|
#include "symboldatabase.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#define GET_SYMBOL_DB(code) \
|
#define GET_SYMBOL_DB(code) \
|
||||||
errout.str(""); \
|
errout.str(""); \
|
||||||
|
@ -759,8 +760,7 @@ private:
|
||||||
// three elements: varId 0 also counts via a fake-entry
|
// three elements: varId 0 also counts via a fake-entry
|
||||||
ASSERT(v && db->getVariableListSize() == 3);
|
ASSERT(v && db->getVariableListSize() == 3);
|
||||||
|
|
||||||
const Variable* v_must_be_null = db->getVariableFromVarId(3);
|
ASSERT_THROW(db->getVariableFromVarId(3), std::out_of_range);
|
||||||
ASSERT(v_must_be_null == nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasRegularFunction() {
|
void hasRegularFunction() {
|
||||||
|
|
Loading…
Reference in New Issue