From a99fd364ef21320b2752f268182c2dfddf0965c1 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 16 Oct 2014 19:12:02 +0200 Subject: [PATCH] Restored functionality to detect std::string(0) calls as null pointer dereferences (#6189) --- lib/checknullpointer.cpp | 2 +- test/testnullpointer.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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