Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
symboldatabase: Fix potential null pointer dereference (#1072)
There is a potential `nullPointer` dereference in symboldatabase. This PR attempts to fix this. Additionally, this could be detected by Cppcheck as well. Here is a reduced and compilable testcase, where Cppcheck fails to detect a potential `nullPointer` dereference: ``` class Scope { public: bool bar(); int *definedType; }; int f(Scope *new_scope) { int ret = 1; if (new_scope) { if (new_scope->bar()) { if (!new_scope->definedType) {} // check for null ret = *new_scope->definedType; // dereference } } return ret; } ``` The corresponding ticket on track, addressing the false negative: https://trac.cppcheck.net/ticket/8375
- Loading branch information
ee1ba85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, it seems to me that now we have a real
nullPointer
dereference instead of a potentialnullPointer
dereference.Why do you dereference
new_scope->definedType
in line 133, if it is known to be zero from line 131?Shouldn't we just
break
at this point?ee1ba85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Thats true, my fault.
ee1ba85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 82c963d