From ef30da51bfd94ac1f3dc7ffc440672d239a8753e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 29 Aug 2011 19:16:52 +0200 Subject: [PATCH] Fixed #3034 (Cppcheck crash on specific file (truecrypt).) --- lib/checkbufferoverrun.cpp | 2 ++ test/testbufferoverrun.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 27471b639..134d5fcf2 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -720,6 +720,8 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p ftok = ftok->next()->link()->next()->link(); if (Token::simpleMatch(ftok, "} else {")) ftok = ftok->tokAt(2)->link(); + if (!ftok) + break; continue; } } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 2f26daa79..e6b3dbb9a 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -209,6 +209,7 @@ private: TEST_CASE(crash1); // Ticket #1587 - crash TEST_CASE(crash2); // Ticket #2607 - crash + TEST_CASE(crash3); // Ticket #3034 - crash TEST_CASE(executionPaths1); TEST_CASE(executionPaths2); @@ -2900,6 +2901,18 @@ private: check("struct C {} {} x"); } + void crash3() + { + check("void a(char *p) {\n" + " f( { if(finally_arg); } );\n" + "}\n" + "\n" + "void b() {\n" + " char arr[64];\n" + " a(arr);\n" + "}"); + } + void epcheck(const char code[]) {