Fixed #3596 (memory leak false positive on libedit sources)

This commit is contained in:
Daniel Marjamäki 2012-02-27 18:55:36 +01:00
parent 2ac907b40a
commit 527d3791e6
2 changed files with 8 additions and 1 deletions

View File

@ -4763,7 +4763,9 @@ void Tokenizer::simplifyCasts()
for (Token *tok = _tokens; tok; tok = tok->next()) { for (Token *tok = _tokens; tok; tok = tok->next()) {
// #2897 : don't remove cast in such cases: // #2897 : don't remove cast in such cases:
// *((char *)a + 1) = 0; // *((char *)a + 1) = 0;
if (!tok->isName() && Token::simpleMatch(tok->next(), "* (")) { // #3596 : remove cast when casting a function pointer:
// (*(void (*)(char *))fp)(x);
if (!tok->isName() && Token::simpleMatch(tok->next(), "* (") && !Token::Match(tok->linkAt(2), ") %var%")) {
tok = tok->linkAt(2); tok = tok->linkAt(2);
continue; continue;
} }

View File

@ -74,6 +74,7 @@ private:
TEST_CASE(removeCast7); TEST_CASE(removeCast7);
TEST_CASE(removeCast8); TEST_CASE(removeCast8);
TEST_CASE(removeCast9); TEST_CASE(removeCast9);
TEST_CASE(removeCast10);
TEST_CASE(inlineasm); TEST_CASE(inlineasm);
@ -781,6 +782,10 @@ private:
ASSERT_EQUALS("f ( ( double ) v1 * v2 )", tokenizeAndStringify("f((double)(v1)*v2)", true)); ASSERT_EQUALS("f ( ( double ) v1 * v2 )", tokenizeAndStringify("f((double)(v1)*v2)", true));
} }
void removeCast10() {
ASSERT_EQUALS("; ( * f ) ( p ) ;", tokenizeAndStringify("; (*(void (*)(char *))f)(p);", true));
}
void inlineasm() { void inlineasm() {
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("asm { mov ax,bx };")); ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("asm { mov ax,bx };"));
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("_asm { mov ax,bx };")); ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("_asm { mov ax,bx };"));