diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index d9e210bef..a5fcf58fd 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -863,6 +863,12 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::liststr() == "for") || (tok->str() == "while")) { + if (Token::simpleMatch(tok, "while ( true )")) + { + addtoken("while1"); + tok = tok->next()->link(); + continue; + } addtoken("loop"); isloop = true; } @@ -1320,6 +1326,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all) done = false; } + // Reduce "while1 ;" => "use ;" + if (Token::simpleMatch(tok2, "while1 ;")) + { + tok2->str("use"); + done = false; + } + // Delete if block: "alloc; if return use ;" if (Token::Match(tok2, "alloc ; if return use ; !!else")) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 0b50fddf3..11454edf1 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -350,6 +350,7 @@ private: ASSERT_EQUALS(";;loop{}", getcode("char *s; for (a;b;c) { }", "s")); ASSERT_EQUALS(";;loop{alloc;}", getcode("char *s; for (a;b;c) { s=malloc(10); }", "s")); ASSERT_EQUALS(";;do{}loop;", getcode("char *s; do { } while (a);", "s")); + ASSERT_EQUALS(";;while1{}", getcode("char *s; while(true) { }", "s")); // asprintf.. ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"xyz\");", "s")); @@ -485,6 +486,8 @@ private: ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;")); ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;")); + ASSERT_EQUALS("; alloc ; use ;", simplifycode("; alloc ; while1 { if { dealloc ; return ; } }")); + // callfunc.. ASSERT_EQUALS("; callfunc ;\n;", simplifycode(";callfunc;"));