diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index 951ee3c68..b17af6b7a 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -546,58 +546,6 @@ void CheckMemoryLeakClass::erase(TOKEN *begin, const TOKEN *end) */ void CheckMemoryLeakClass::simplifycode(TOKEN *tok) { - // Remove "do"... - // do { x } while (y); - // => - // { x } while(y) { x }" - for ( TOKEN *tok2 = tok; tok2; tok2 = tok2->next ) - { - if ( ! TOKEN::Match(tok2->next, "do") ) - continue; - - // Remove the next token "do" - erase( tok2, tok2->tokAt(2) ); - tok2 = tok2->next; - - // Find the end of the "do" block.. - TOKEN *tok2_; - int indentlevel = 0; - for ( tok2_ = tok2; tok2_ && indentlevel>=0; tok2_ = tok2_->next ) - { - if ( tok2_->str() == "{" ) - ++indentlevel; - - else if ( tok2_->str() == "}" ) - --indentlevel; - - else if ( indentlevel == 0 && (tok2_->next->str() == ";") ) - break; - } - - // End not found? - if ( ! tok2_ ) - continue; - - // Copy code.. - indentlevel = 0; - do - { - if ( tok2->str() == "{" ) - ++indentlevel; - else if ( tok2->str() == "}" ) - --indentlevel; - - // Copy token.. - instoken( tok2_, tok2->aaaa() ); - - // Next token.. - tok2 = tok2->next; - tok2_ = tok2_->next; - } - while ( tok2 && indentlevel > 0 ); - } - - // reduce the code.. bool done = false; while ( ! done ) @@ -704,6 +652,14 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok) erase(tok2,tok2->tokAt(8)); done = false; } + + // Reduce "do { alloc ; } " => "alloc ;" + if ( TOKEN::Match(tok2->next, "do { alloc ; }") ) + { + erase(tok2, tok2->tokAt(3)); + erase(tok2->next, tok2->tokAt(3)); + done = false; + } // Replace "loop ;" with ";" if ( TOKEN::Match(tok2->next, "loop ;") ) diff --git a/testmemleak.cpp b/testmemleak.cpp index 9c5ce9f16..33298ea31 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -607,8 +607,10 @@ private: " }\n" " while (!str);\n" " return str;\n" - "}\n" ); - ASSERT_EQUALS( std::string("[test.cpp:5]: Memory leak: str\n"), errout.str() ); + "}\n" ); + std::string err( errout.str() ); + std::cout << err; + ASSERT_EQUALS( std::string("[test.cpp:5]: Memory leak: str\n"), err ); }