Fixed #6238 (false positive with double fopen)

This commit is contained in:
Frank Zingsheim 2014-11-20 22:19:39 +01:00
parent d4e59065df
commit 9497732ac8
2 changed files with 8 additions and 2 deletions

View File

@ -1036,7 +1036,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
}
} else if (tok2->varId() && 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;
}

View File

@ -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"));