Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 236d0eb178d0fa2a11aa5cff1cf2eae808f94cc3 1 parent 9994218
Reijo Tomperi authored September 28, 2011
3  lib/checkuninitvar.cpp
@@ -651,7 +651,8 @@ class UninitVar : public ExecutionPath
651 651
                 return tok.next()->link();
652 652
 
653 653
             // deallocate pointer
654  
-            if (Token::Match(&tok, "free|kfree|fclose ( %var% )"))
  654
+            if (Token::Match(&tok, "free|kfree|fclose ( %var% )") ||
  655
+                Token::Match(&tok, "realloc ( %var%"))
655 656
             {
656 657
                 dealloc_pointer(checks, tok.tokAt(2));
657 658
                 return tok.tokAt(3);
12  test/testuninitvar.cpp
@@ -85,6 +85,18 @@ class TestUninitVar : public TestFixture
85 85
                        "}\n");
86 86
         ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
87 87
 
  88
+        checkUninitVar("void foo() {\n"
  89
+                       "    int *p;\n"
  90
+                       "    realloc(p,10);\n"
  91
+                       "}\n");
  92
+        ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout.str());
  93
+
  94
+        checkUninitVar("void foo() {\n"
  95
+                       "    int *p = NULL;\n"
  96
+                       "    realloc(p,10);\n"
  97
+                       "}\n");
  98
+        ASSERT_EQUALS("", errout.str());
  99
+
88 100
         // dereferencing uninitialized pointer..
89 101
         checkUninitVar("static void foo()\n"
90 102
                        "{\n"

0 notes on commit 236d0eb

Please sign in to comment.
Something went wrong with that request. Please try again.