From dbc6771a0b99808add10f089650206de57d025f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 4 Feb 2018 22:30:08 +0100 Subject: [PATCH] Uninitialized variables: Fix FP for unknown macro like 'list_for_each' --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index f3e2c98d5..cb4e0c2c2 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1059,7 +1059,7 @@ int CheckUninitVar::isFunctionParUsage(const Token *vartok, bool pointer, Alloc if (!start) return -1; - if (Token::simpleMatch(start->link(), ") {")) + if (Token::simpleMatch(start->link(), ") {") && Token::Match(start->previous(), "if|for|while|switch")) return (!pointer || alloc == NO_ALLOC); // is this a function call? diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index d44e0deaa..196026771 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2874,6 +2874,13 @@ private: " buf[1] = buf[0];\n" "}"); ASSERT_EQUALS("", errout.str()); + + // unknown macro + checkUninitVar("void f() {\n" + " struct listnode *item;\n" + " list_for_each(item, &key_list) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void uninitvar2_value() {