From 812bc6bdaf9bca23da0c0aa61ff23dec08066900 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sat, 27 Sep 2014 11:03:58 +0200 Subject: [PATCH] CheckVaarg::va_list_usage(): Bailout when try{} block is encountered (#6186) --- lib/checkvaarg.cpp | 5 ++++- test/testvaarg.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/checkvaarg.cpp b/lib/checkvaarg.cpp index 8e25fca71..d7801dd16 100644 --- a/lib/checkvaarg.cpp +++ b/lib/checkvaarg.cpp @@ -114,7 +114,10 @@ void CheckVaarg::va_list_usage() tok = tok->linkAt(1); } else if (Token::Match(tok, "throw|return")) exitOnEndOfStatement = true; - else if (!open && tok->varId() == var->declarationId()) + else if (_tokenizer->isCPP() && tok->str() == "try") { + open = false; + break; + } else if (!open && tok->varId() == var->declarationId()) va_list_usedBeforeStartedError(tok, var->name()); else if (exitOnEndOfStatement && tok->str() == ";") break; diff --git a/test/testvaarg.cpp b/test/testvaarg.cpp index 8e7c6f11f..8d152f39b 100644 --- a/test/testvaarg.cpp +++ b/test/testvaarg.cpp @@ -116,6 +116,18 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + // #6186 + check("void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\n" + " va_list arg_ptr;\n" + " va_start(arg_ptr, szBuffer);\n" + " try {\n" + " throw sth;\n" + " } catch(...) {\n" + " va_end(arg_ptr);\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\n" " va_list arg_ptr;\n" " va_start(arg_ptr, szBuffer);\n"