diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 259b928f0..fe623c4c8 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1757,7 +1757,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all } } - if (Token::Match(vartok->previous(), "= %var% ;|%cop%")) + if (!alloc && Token::Match(vartok->previous(), "= %var% ;|%cop%")) return true; if (Token::Match(vartok->previous(), "? %var%")) { diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index faa5052f6..aa3f8a353 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -3348,6 +3348,12 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar2("void f() {\n" + " char *p = malloc(100);\n" + " x = p;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // function parameter (treat it as initialized until malloc is used) checkUninitVar2("int f(int *p) {\n" " if (*p == 1) {}\n" // no error