File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1223,7 +1223,12 @@ void CheckNullPointer::nullPointerDefaultArgument()
12231223 }
12241224 }
12251225 if (dependsOnPointer && Token::simpleMatch (endOfCondition, " ) {" )) {
1226- tok = endOfCondition->next ()->link ();
1226+ const Token *endOfIf = endOfCondition->next ()->link ();
1227+ for (; tok != endOfIf; tok = tok->next ()) {
1228+ // If a pointer is assigned a new value, stop considering it.
1229+ if (Token::Match (tok, " %var% =" ))
1230+ pointerArgs.erase (tok->varId ());
1231+ }
12271232 continue ;
12281233 }
12291234 }
@@ -1232,7 +1237,7 @@ void CheckNullPointer::nullPointerDefaultArgument()
12321237 continue ;
12331238
12341239 // If a pointer is assigned a new value, stop considering it.
1235- if (Token::Match (tok, " %var% = %any% " ))
1240+ if (Token::Match (tok, " %var% =" ))
12361241 pointerArgs.erase (tok->varId ());
12371242
12381243 if (isPointerDeRef (tok, unknown, symbolDatabase))
Original file line number Diff line number Diff line change @@ -2193,6 +2193,14 @@ class TestNullPointer : public TestFixture {
21932193 " }" );
21942194 ASSERT_EQUALS (" " , errout.str ());
21952195
2196+ check (" void f(int *p = 0) {\n "
2197+ " int y;\n "
2198+ " if (p == 0)\n "
2199+ " p = &y;\n "
2200+ " *p = 0;\n "
2201+ " }" );
2202+ ASSERT_EQUALS (" " , errout.str ());
2203+
21962204 check (" void f(int *p = 0) {\n "
21972205 " if (a != 0)\n "
21982206 " *p = 0;\n "
You can’t perform that action at this time.
0 commit comments