From 512e22d1bae7e9fc1462ee182e27c4efce8ac153 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Thu, 8 May 2014 20:51:18 +0200 Subject: [PATCH] Ticket #5315: Memory leak analysis confused by ((variable).attribute) notation. --- lib/tokenize.cpp | 2 +- test/testmemleak.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 50dc81370..14cd4b6c6 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7022,7 +7022,7 @@ bool Tokenizer::simplifyRedundantParentheses() ret = true; } - if (Token::Match(tok->previous(), "[,;{}] ( %var% ) .")) { + if (Token::Match(tok->previous(), "[(,;{}] ( %var% ) .")) { // Remove the parentheses tok->deleteThis(); tok->deleteNext(); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index f3f4863fb..3c83d1420 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -5620,6 +5620,7 @@ private: TEST_CASE(trac5030); TEST_CASE(varid); // #5201: Analysis confused by (variable).attribute notation + TEST_CASE(varid_2); // #5315: Analysis confused by ((variable).attribute) notation } void err() { @@ -6158,6 +6159,16 @@ private: "}", /*fname=*/0, /*isCPP=*/false); TODO_ASSERT_EQUALS("[test.c:9]: (error) Memory leak: s.state_check_buff\n", "", errout.str()); } + + void varid_2() { // #5315 + check("typedef struct foo { char *realm; } foo;\n" + "void build_principal() {\n" + " foo f;\n" + " ((f)->realm) = strdup(realm);\n" + " if(f->realm == NULL) {}\n" + "}", /*fname=*/0, /*isCPP=*/false); + ASSERT_EQUALS("[test.c:6]: (error) Memory leak: f.realm\n", errout.str()); + } };