File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -614,6 +614,8 @@ class UninitVar : public ExecutionPath {
614614 if (Token::Match (&tok, " free|kfree|fclose ( %var% )" ) ||
615615 Token::Match (&tok, " realloc ( %var%" )) {
616616 dealloc_pointer (checks, tok.tokAt (2 ));
617+ if (tok.str () == " realloc" )
618+ ExecutionPath::bailOutVar (checks, tok.tokAt (2 )->varId ());
617619 return tok.tokAt (3 );
618620 }
619621
Original file line number Diff line number Diff line change @@ -106,6 +106,13 @@ class TestUninitVar : public TestFixture {
106106 " }" );
107107 ASSERT_EQUALS (" [test.cpp:3]: (error) Uninitialized variable: p\n " , errout.str ());
108108
109+ checkUninitVar (" void foo() {\n " // #5240
110+ " char *p = malloc(100);\n "
111+ " char *tmp = realloc(p,1000);\n "
112+ " if (!tmp) free(p);\n "
113+ " }" );
114+ ASSERT_EQUALS (" " , errout.str ());
115+
109116 checkUninitVar (" void foo() {\n "
110117 " int *p = NULL;\n "
111118 " realloc(p,10);\n "
You can’t perform that action at this time.
0 commit comments