From 9a760b9654411b2c18f1792027657f7950632b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 18 Feb 2011 20:05:44 +0100 Subject: [PATCH] Fixed #2582 (segmentation fault of cppcheck ( if() )) --- lib/checknullpointer.cpp | 2 +- test/testnullpointer.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 8d3219afe..698476b12 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -554,7 +554,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() { // goto the end paranthesis const Token *endpar = tok->next()->link(); - const Token *endbody = endpar ? endpar->next()->link() : 0; + const Token *endbody = Token::simpleMatch(endpar, ") {") ? endpar->next()->link() : 0; if (endbody && Token::Match(endbody->tokAt(-3), "[;{}] %var% ;") && isUpper(endbody->tokAt(-2)->str())) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 35b239974..03a7d0e1b 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -890,6 +890,9 @@ private: " };\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #2582 - segmentation fault + check("if()"); } // Test CheckNullPointer::nullConstantDereference