From 2b54f00c87c970cbac3d1d579d6a08b4d8935124 Mon Sep 17 00:00:00 2001 From: Erik Lax Date: Sat, 22 Oct 2011 12:36:45 +0200 Subject: [PATCH] Fixed #3238 (Crash in obsolete functions check.) --- lib/checkobsoletefunctions.cpp | 2 +- test/testobsoletefunctions.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkobsoletefunctions.cpp b/lib/checkobsoletefunctions.cpp index 8d53bfca4..fe51fb34a 100644 --- a/lib/checkobsoletefunctions.cpp +++ b/lib/checkobsoletefunctions.cpp @@ -47,7 +47,7 @@ void CheckObsoleteFunctions::obsoleteFunctions() if (tok->isName() && tok->varId()==0 && (tok->next() && tok->next()->str() == "(") && (!Token::Match(tok->previous(), ".|::|:|,") || Token::simpleMatch(tok->previous()->previous(), "std :: gets"))) { // c function declaration? - if ((tok->next()->link()->next() && tok->next()->link()->next()->str() == ";") && (tok->previous()->str() == "*" || tok->previous()->isName())) { + if ((tok->next()->link()->next() && tok->next()->link()->next()->str() == ";") && (tok->previous() && (tok->previous()->str() == "*" || tok->previous()->isName()))) { continue; } diff --git a/test/testobsoletefunctions.cpp b/test/testobsoletefunctions.cpp index 8cbb4fe8f..63f8551c0 100644 --- a/test/testobsoletefunctions.cpp +++ b/test/testobsoletefunctions.cpp @@ -64,6 +64,8 @@ private: // function with body TEST_CASE(test_function_with_body); + // null pointer dereference in obsoleteFunctions + TEST_CASE(ticket3238); } void check(const char code[]) { @@ -288,6 +290,10 @@ private: ASSERT_EQUALS("", errout.str()); } + void ticket3238() { + check("__FBSDID(\"...\");\n"); + ASSERT_EQUALS("", errout.str()); + } };