From 7b986c831d7ee782beae919b550b71aa097637ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 23 Jan 2010 07:57:57 +0100 Subject: [PATCH] Report when using uninitialized function pointer --- lib/checkother.cpp | 5 +++++ test/testother.cpp | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index bb835c99b..410261836 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1706,6 +1706,11 @@ private: } } + if (Token::simpleMatch(tok.next(), "(")) + { + use_pointer(foundError, checks, &tok); + } + if (Token::Match(tok.tokAt(-2), "[;{}] *")) { if (Token::simpleMatch(tok.next(), "=")) diff --git a/test/testother.cpp b/test/testother.cpp index 6614fed17..8a4674d4b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1716,6 +1716,14 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str()); + + // using uninitialized function pointer.. + checkUninitVar("void foo()\n" + "{\n" + " void (*f)();\n" + " f();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n", errout.str()); }