From 9497732ac818f36ea2a691a585cf40353b47a1a5 Mon Sep 17 00:00:00 2001 From: Frank Zingsheim Date: Thu, 20 Nov 2014 22:19:39 +0100 Subject: [PATCH] Fixed #6238 (false positive with double fopen) --- lib/checkmemoryleak.cpp | 3 ++- test/testmemleak.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 3bf56953c..8091a75da 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1036,7 +1036,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listvarId() && extravar.find(tok2->varId()) != extravar.end()) { dep = true; - } else if (tok2->varId() == varid && tok2->next()->isConstOp()) + } else if (tok2->varId() == varid && + (tok2->next()->isConstOp() || tok2->previous()->isConstOp())) dep = true; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index da221dfe5..d050d6af8 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -453,7 +453,12 @@ private: ASSERT_EQUALS(";;if{}", getcode("char *s; if (a) { }", "s")); ASSERT_EQUALS(";;dealloc;ifv{}", getcode("FILE *f; if (fclose(f)) { }", "f")); ASSERT_EQUALS(";;if(!var){}else{}", getcode("char *s; if (!s) { } else { }", "s")); - ASSERT_EQUALS(";;if{}", getcode("char *s; if (a && s) { }", "s")); + TODO_ASSERT_EQUALS(";;ifv{}",";;if{}", getcode("char *s; if (a && s) { }", "s")); + ASSERT_EQUALS(";;ifv{}", getcode("char *s; if (s && a) { }", "s")); + ASSERT_EQUALS(";;;ifv{}", getcode("char *s; int a; if (a && s) { }", "s")); + ASSERT_EQUALS(";;;ifv{}", getcode("char *s; int a; if (s && a) { }", "s")); + ASSERT_EQUALS(";;ifv{}", getcode("char *s; if (a || s) { }", "s")); + ASSERT_EQUALS(";;ifv{}", getcode("char *s; if (s || a) { }", "s")); ASSERT_EQUALS(";;if(!var){}", getcode("char *s; if (a && !s) { }", "s")); ASSERT_EQUALS(";;ifv{}", getcode("char *s; if (foo(!s)) { }", "s")); ASSERT_EQUALS(";;;if{dealloc;};if{dealloc;return;}assign;returnuse;", getcode("char *buf, *tmp; tmp = realloc(buf, 40); if (!(tmp)) { free(buf); return; } buf = tmp; return buf;", "buf"));