ericsesterhenn: Fixed #1091 (improve check: nullpointer dereference not detected)
This commit is contained in:
parent
763e3d9eb5
commit
b3b07321ca
|
@ -1198,6 +1198,8 @@ private:
|
|||
dereference(foundError, checks, &tok);
|
||||
else if (Token::Match(tok.next(), ". %var%"))
|
||||
dereference(foundError, checks, &tok);
|
||||
else if (Token::Match(tok.previous(), "[;{}] %var% [ %num% ] ="))
|
||||
dereference(foundError, checks, &tok);
|
||||
else
|
||||
bailOutVar(checks, tok.varId());
|
||||
}
|
||||
|
|
|
@ -615,6 +615,8 @@ private:
|
|||
settings._checkCodingStyle = true;
|
||||
CheckOther checkOther(&tokenizer, &settings, this);
|
||||
checkOther.nullPointer();
|
||||
|
||||
tokenizer.simplifyTokenList();
|
||||
checkOther.executionPaths();
|
||||
}
|
||||
|
||||
|
@ -905,6 +907,14 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:8]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||
|
||||
checkNullPointer("static void foo()\n"
|
||||
"{\n"
|
||||
" int *p = 0;\n"
|
||||
" int *q = p;\n"
|
||||
" q[0] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: q\n", errout.str());
|
||||
|
||||
// no false positive..
|
||||
checkNullPointer("static void foo()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue