diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 923e4c753..71d232f48 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -486,9 +486,28 @@ private: if (Token::Match(tok.tokAt(-2), "[;{}] *")) { if (Token::simpleMatch(tok.next(), "=")) - init_pointer(checks, &tok); + { + // is the pointer used in the rhs? + bool used = false; + for (const Token *tok2 = tok.tokAt(2); tok2; tok2 = tok2->next()) + { + if (Token::Match(tok2, "[,;=(]")) + break; + else if (Token::Match(tok2, "* %varid%", tok.varId())) + { + used = true; + break; + } + } + if (used) + use_pointer(checks, &tok); + else + init_pointer(checks, &tok); + } else + { use_pointer(checks, &tok); + } return &tok; } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 50ef4c239..402df2c6f 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -376,8 +376,7 @@ private: " char *s = malloc(100);\n" " *s += 10;\n" "}\n"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str()); - ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str()); checkUninitVar("void f()\n" "{\n"