From 9a61559eca34e5f97ccdc908082a299dfe853c82 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 2 Jun 2016 09:32:45 +0200 Subject: [PATCH] Fixed false positive va_list_usedBeforeStarted (#7527) --- lib/checkvaarg.cpp | 2 +- test/testvaarg.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/checkvaarg.cpp b/lib/checkvaarg.cpp index 469fc1a7b..c8dd172e0 100644 --- a/lib/checkvaarg.cpp +++ b/lib/checkvaarg.cpp @@ -122,7 +122,7 @@ void CheckVaarg::va_list_usage() } open = nopen; tok = tok->linkAt(1); - } else if (Token::Match(tok, "throw|return")) + } else if (Token::Match(tok, "throw|return|break")) exitOnEndOfStatement = true; else if (_tokenizer->isCPP() && tok->str() == "try") { open = false; diff --git a/test/testvaarg.cpp b/test/testvaarg.cpp index e87f5f23c..eed7791fb 100644 --- a/test/testvaarg.cpp +++ b/test/testvaarg.cpp @@ -200,6 +200,22 @@ private: " va_end(v2);\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #7527 + check("void foo(int flag1, int flag2, ...) {\n" + " switch (flag1) {\n" + " default:\n" + " va_list vargs;\n" + " va_start(vargs, flag2);\n" + " if (flag2) {\n" + " va_end(vargs);\n" + " break;\n" + " }\n" + " int data = va_arg(vargs, int);\n" + " va_end(vargs);\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void va_start_subsequentCalls() {