Skip to content

Commit 9497732

Browse files
committed
Fixed danmar#6238 (false positive with double fopen)
1 parent d4e5906 commit 9497732

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/checkmemoryleak.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
10361036
}
10371037
} else if (tok2->varId() && extravar.find(tok2->varId()) != extravar.end()) {
10381038
dep = true;
1039-
} else if (tok2->varId() == varid && tok2->next()->isConstOp())
1039+
} else if (tok2->varId() == varid &&
1040+
(tok2->next()->isConstOp() || tok2->previous()->isConstOp()))
10401041
dep = true;
10411042
}
10421043

test/testmemleak.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,12 @@ class TestMemleakInFunction : public TestFixture {
453453
ASSERT_EQUALS(";;if{}", getcode("char *s; if (a) { }", "s"));
454454
ASSERT_EQUALS(";;dealloc;ifv{}", getcode("FILE *f; if (fclose(f)) { }", "f"));
455455
ASSERT_EQUALS(";;if(!var){}else{}", getcode("char *s; if (!s) { } else { }", "s"));
456-
ASSERT_EQUALS(";;if{}", getcode("char *s; if (a && s) { }", "s"));
456+
TODO_ASSERT_EQUALS(";;ifv{}",";;if{}", getcode("char *s; if (a && s) { }", "s"));
457+
ASSERT_EQUALS(";;ifv{}", getcode("char *s; if (s && a) { }", "s"));
458+
ASSERT_EQUALS(";;;ifv{}", getcode("char *s; int a; if (a && s) { }", "s"));
459+
ASSERT_EQUALS(";;;ifv{}", getcode("char *s; int a; if (s && a) { }", "s"));
460+
ASSERT_EQUALS(";;ifv{}", getcode("char *s; if (a || s) { }", "s"));
461+
ASSERT_EQUALS(";;ifv{}", getcode("char *s; if (s || a) { }", "s"));
457462
ASSERT_EQUALS(";;if(!var){}", getcode("char *s; if (a && !s) { }", "s"));
458463
ASSERT_EQUALS(";;ifv{}", getcode("char *s; if (foo(!s)) { }", "s"));
459464
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"));

0 commit comments

Comments
 (0)