From 3f30753122a282ae688096a7c0e425ec8acfbe3d Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sun, 9 Mar 2014 08:17:24 +0100 Subject: [PATCH] Fixed #5537 (crash: clang ./lib/Basic/FileManager.cpp , since 354e84e7c85b01e5d1fc29ecb4f2e504271cb2e0 , /lib/symboldatabase.h:288) --- lib/checkautovariables.cpp | 2 +- test/testautovariables.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 85545ee88..86ec7dbf3 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -202,7 +202,7 @@ void CheckAutoVariables::autoVariables() errorInvalidDeallocation(tok); } else if (Token::Match(tok, "free ( & %var% ) ;") || Token::Match(tok, "delete [| ]| (| & %var% !![")) { tok = Token::findmatch(tok->next(), "%var%"); - if (tok->variable()->isLocal()) + if (tok && tok->variable() && tok->variable()->isLocal()) errorInvalidDeallocation(tok); } } diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index d9079e961..9bb27f688 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -80,6 +80,7 @@ private: TEST_CASE(testautovar10); // ticket #2930 - void f(char *p) { p = '\0'; } TEST_CASE(testautovar11); // ticket #4641 - fp, assign local struct member address to function parameter TEST_CASE(testautovar12); // ticket #5024 - crash + TEST_CASE(testautovar13); // ticket #5537 - crash TEST_CASE(testautovar_array1); TEST_CASE(testautovar_array2); TEST_CASE(testautovar_return1); @@ -359,6 +360,16 @@ private: "UNKNOWN_MACRO_EXPANDING_TO_SIGNATURE { custom_type a(var); }"); } + void testautovar13() { // Ticket #5537 + check("class FileManager {\n" + " FileManager() : UniqueRealDirs(*new UniqueDirContainer())\n" + " {}\n" + " ~FileManager() {\n" + " delete &UniqueRealDirs;\n" + " }\n" + "};\n"); + } + void testautovar_array1() { check("void func1(int* arr[2])\n" "{\n"