From ae3ff7d3768aaf573c74fba2c5a4956e2e8e2edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 30 Dec 2009 20:37:11 +0100 Subject: [PATCH] Fixed #1087 (uninitialized data not detected 'char z = *str') --- lib/checkother.cpp | 8 +++++++- test/testother.cpp | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 988cc1f50..4b642c1fb 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1722,7 +1722,7 @@ private: if (Token::Match(tok.tokAt(-2), "[,(=] *")) { - use(foundError, checks, &tok); + use_pointer(foundError, checks, &tok); return &tok; } } @@ -1744,6 +1744,12 @@ private: use_array(foundError, checks, *it); } + else if (Token::Match(&tok, "! %var% )")) + { + use(foundError, checks, &tok); + return false; + } + return ExecutionPath::parseCondition(tok, checks); } }; diff --git a/test/testother.cpp b/test/testother.cpp index 3a15e7df6..138f0d115 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1403,6 +1403,15 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("void f()\n" + "{\n" + " char *s = malloc(100);\n" + " if (!s)\n" + " return;\n" + " char c = *s;\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:6]: (error) Data is allocated but not initialized: s\n", errout.str()); + // struct.. checkUninitVar("void f()\n" "{\n"