From 28b8bc57a87dbb3936d6554d204f0db85597a4b0 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 7 May 2017 08:32:48 +0200 Subject: [PATCH] CheckVaarg::va_list_usage(): Bailout on "goto" (#8043) --- lib/checkvaarg.cpp | 2 +- test/testvaarg.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/checkvaarg.cpp b/lib/checkvaarg.cpp index 24081b8d8..674b3b916 100644 --- a/lib/checkvaarg.cpp +++ b/lib/checkvaarg.cpp @@ -132,7 +132,7 @@ void CheckVaarg::va_list_usage() tok = scope->classEnd; if (!tok) return; - } else if (_tokenizer->isCPP() && tok->str() == "try") { + } else if (tok->str() == "goto" || (_tokenizer->isCPP() && tok->str() == "try")) { open = false; break; } else if (!open && tok->varId() == var->declarationId()) diff --git a/test/testvaarg.cpp b/test/testvaarg.cpp index 846f41c85..b7328d01d 100644 --- a/test/testvaarg.cpp +++ b/test/testvaarg.cpp @@ -263,6 +263,21 @@ private: " }\n" "}"); ASSERT_EQUALS("[test.cpp:13]: (error) va_list 'args' was opened but not closed by va_end().\n", errout.str()); + + // #8043 + check("void redisvFormatCommand(char *format, va_list ap, bool flag) {\n" + " va_list _cpy;\n" + " va_copy(_cpy, ap);\n" + " if (flag)\n" + " goto fmt_valid;\n" + " va_end(_cpy);\n" + " goto format_err;\n" + "fmt_valid:\n" + " sdscatvprintf(curarg, _format, _cpy);\n" + " va_end(_cpy);\n" + "format_err:\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void va_start_subsequentCalls() {