From eba827bc4be6aeda65196433ec0227aa09a72289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 21 Oct 2010 19:42:09 +0200 Subject: [PATCH] Fixed #2112 (Crash scanning qtcreator sources) --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index ff455e8fa..aba91179d 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1282,7 +1282,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::liststr() == "(") f.push(tok2->previous()); - else if (tok2->str() == ")") + else if (!f.empty() && tok2->str() == ")") f.pop(); if (tok2->varId() == varid) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 33723e5df..b953d0a0d 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -569,6 +569,13 @@ private: // call memcpy in class function.. ASSERT_EQUALS(";;alloc;;", getcode("char *s; s = new char[10]; memcpy(s,a);", "s", true)); + + // #2112 - Segmentation fault in the getcode function + getcode("page *one = foo();\n" + "ASSERT(one, return 0)\n" + "const int two = rand();\n" + "return 0;\n" + "}", "one"); }