diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 7dcf4abe2..ce60a3f4c 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -431,7 +431,7 @@ void CheckNullPointer::nullConstantDereference() ovar = tok->variable(); else if (Token::Match(tok, "%var% =|+ 0 )|]|,|;|+")) ovar = tok->variable(); - if (ovar && !ovar->isPointer() && !ovar->isArray() && ovar->isStlStringType() && !tok->tokAt(2)->isLiteral()) + if (ovar && !ovar->isPointer() && !ovar->isArray() && ovar->isStlStringType() && tok->tokAt(2)->originalName() != "'\\0'") nullPointerError(tok); } } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 9c145a4c0..d25f8cc91 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -2026,6 +2026,8 @@ private: "}", true); ASSERT_EQUALS("[test.cpp:9]: (error) Possible null pointer dereference: p\n" "[test.cpp:10]: (error) Possible null pointer dereference: p\n" + "[test.cpp:3]: (error) Null pointer dereference\n" + "[test.cpp:5]: (error) Null pointer dereference\n" "[test.cpp:7]: (error) Null pointer dereference\n" "[test.cpp:8]: (error) Null pointer dereference\n" /* TODO: handle std::string