Skip to content

Commit 970fda9

Browse files
committed
ValueFlow: Fixed nullpointer FP warning in checksizeof
1 parent 263582d commit 970fda9

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

lib/valueflow.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ static bool valueFlowForward(Token * const startToken,
825825
errorLogger,
826826
tok2,
827827
"no simplification of " + tok2->str() + " within " + (Token::Match(parent,"[?:]") ? "?:" : parent->str()) + " expression");
828+
while (parent && parent->str() != "(")
829+
parent = parent->astParent();
830+
if (parent)
831+
tok2 = const_cast<Token*>(parent->link());
828832
continue;
829833
}
830834

test/testvalueflow.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,23 @@ class TestValueFlow : public TestFixture {
940940
"}";
941941
ASSERT_EQUALS(true, testValueOfX(code, 3U, 4));
942942

943+
// protected usage with &&
944+
code = "void f(const Token* x) {\n"
945+
" if (x) {}\n"
946+
" for (; x && \n"
947+
" x->str() != y; x = x->next()) {}\n"
948+
"}";
949+
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
950+
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
951+
952+
code = "void f(const Token* x) {\n"
953+
" if (x) {}\n"
954+
" if (x && \n"
955+
" x->str() != y) {}\n"
956+
"}";
957+
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 3U, 0));
958+
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
959+
943960
// TODO: float
944961
code = "void f(float x) {\n"
945962
" if (x == 0.5) {}\n"

0 commit comments

Comments
 (0)