Add an assertion check to detect a null pointer case

Also preemptively block subsequent dereferences.

Hopefully somebody will eventually hit an assertion failure here and
report back to help me understand how such a situation could possibly
arise, so I can decide whether to remove the assert and leave the new
loop conditional intact or change it to match the intended behavior
(e.g. it's possible `!active || active->empty()` would be preferable in
some scenario).

Spotted by Coverity.
This commit is contained in:
Ignacio R. Morelle 2014-11-19 00:04:16 -03:00
parent 196b5183b1
commit 151aa77d2c

View File

@ -138,7 +138,12 @@ bool persist_file_context::clear_var(const std::string &global, bool immediate)
ret = exists;
}
}
while ((active->empty()) && (!namespace_.lineage_.empty())) {
// TODO: figure out when this is the case and adjust the next loop
// condition accordingly. -- shadowm
assert(active);
while (active && active->empty() && !namespace_.lineage_.empty()) {
name_space prev = namespace_.prev();
active = get_node(cfg_, prev);
if (active == NULL) {