Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix #2813 (False negative: Uninitialized variable not found for realloc)

  • Loading branch information...
commit 236d0eb178d0fa2a11aa5cff1cf2eae808f94cc3 1 parent 9994218
@aggro80 aggro80 authored
Showing with 14 additions and 1 deletion.
  1. +2 −1  lib/checkuninitvar.cpp
  2. +12 −0 test/testuninitvar.cpp
View
3  lib/checkuninitvar.cpp
@@ -651,7 +651,8 @@ class UninitVar : public ExecutionPath
return tok.next()->link();
// deallocate pointer
- if (Token::Match(&tok, "free|kfree|fclose ( %var% )"))
+ if (Token::Match(&tok, "free|kfree|fclose ( %var% )") ||
+ Token::Match(&tok, "realloc ( %var%"))
{
dealloc_pointer(checks, tok.tokAt(2));
return tok.tokAt(3);
View
12 test/testuninitvar.cpp
@@ -85,6 +85,18 @@ class TestUninitVar : public TestFixture
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
+ checkUninitVar("void foo() {\n"
+ " int *p;\n"
+ " realloc(p,10);\n"
+ "}\n");
+ ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout.str());
+
+ checkUninitVar("void foo() {\n"
+ " int *p = NULL;\n"
+ " realloc(p,10);\n"
+ "}\n");
+ ASSERT_EQUALS("", errout.str());
+
// dereferencing uninitialized pointer..
checkUninitVar("static void foo()\n"
"{\n"
Please sign in to comment.
Something went wrong with that request. Please try again.