From b173d5f1176cc7d81fe8a56bc4b76a2c4c445332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 5 Jul 2010 13:16:33 +0200 Subject: [PATCH] Fixed #1817 (False positive: Resource leak (casting)) --- lib/tokenize.cpp | 10 +++++++++- test/testtokenize.cpp | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a2043f7fb..df10b8e50 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4334,7 +4334,7 @@ void Tokenizer::simplifyCasts() } } - if (Token::Match(tok->next(), "dynamic_cast|reinterpret_cast|const_cast|static_cast <")) + while (Token::Match(tok->next(), "dynamic_cast|reinterpret_cast|const_cast|static_cast <")) { Token *tok2 = tok->next(); unsigned int level = 0; @@ -4359,6 +4359,14 @@ void Tokenizer::simplifyCasts() Token::eraseTokens(tok, tok2->tokAt(2)); closeBracket->deleteThis(); } + else + { + break; + } + } + else + { + break; } } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 4c1417b2c..aa00a35c3 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -57,6 +57,7 @@ private: TEST_CASE(removeCast2); TEST_CASE(removeCast3); TEST_CASE(removeCast4); + TEST_CASE(removeCast5); TEST_CASE(inlineasm); @@ -428,6 +429,12 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } + void removeCast5() + { + // ticket #1817 + ASSERT_EQUALS("a . data = f ;", tokenizeAndStringify("a->data = reinterpret_cast(static_cast(f));", true)); + } + void inlineasm() { ASSERT_EQUALS("; asm ( ) ;", tokenizeAndStringify(";asm { mov ax,bx };"));