Fixed #3901 (false positive: (error) Uninitialized variable: temp)

This commit is contained in:
Daniel Marjamäki 2012-06-19 20:07:39 +02:00
parent ce5c38f52c
commit 974225626d
2 changed files with 15 additions and 1 deletions

View File

@ -4466,7 +4466,10 @@ void Tokenizer::simplifyCasts()
// *((char *)a + 1) = 0;
// #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%")) {
if (!tok->isName() &&
Token::simpleMatch(tok->next(), "* (") &&
!Token::Match(tok->linkAt(2), ") %var%") &&
!Token::simpleMatch(tok->linkAt(2), ") &")) {
tok = tok->linkAt(2);
continue;
}
@ -4483,6 +4486,12 @@ void Tokenizer::simplifyCasts()
// Remove cast..
Token::eraseTokens(tok, tok->next()->link()->next());
// Remove '* &'
if (Token::simpleMatch(tok, "* &")) {
tok->deleteNext();
tok->deleteThis();
}
if (tok->str() == ")" && tok->link()->previous()) {
// If there was another cast before this, go back
// there to check it also. e.g. "(int)(char)x"

View File

@ -78,6 +78,7 @@ private:
TEST_CASE(removeCast8);
TEST_CASE(removeCast9);
TEST_CASE(removeCast10);
TEST_CASE(removeCast11);
TEST_CASE(inlineasm);
@ -788,6 +789,10 @@ private:
ASSERT_EQUALS("; ( * f ) ( p ) ;", tokenizeAndStringify("; (*(void (*)(char *))f)(p);", true));
}
void removeCast11() {
ASSERT_EQUALS("; x = 0 ;", tokenizeAndStringify("; *(int *)&x = 0;", true));
}
void inlineasm() {
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("asm { mov ax,bx };"));
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("_asm { mov ax,bx };"));