From 076c1bd06c01dee6295f1c5facc1d668de93e6b5 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 6 Aug 2014 19:34:31 +0200 Subject: [PATCH] Fixed crash in CheckVaarg::va_start_argument (#6032) --- lib/checkvaarg.cpp | 2 +- test/testvaarg.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkvaarg.cpp b/lib/checkvaarg.cpp index 9a1fe68fa..9834773dd 100644 --- a/lib/checkvaarg.cpp +++ b/lib/checkvaarg.cpp @@ -44,7 +44,7 @@ void CheckVaarg::va_start_argument() const Variable* var = param2->variable(); if (var && var->isReference()) referenceAs_va_start_error(param2, var->name()); - if (var->index() + 2 < function->argCount() && _settings->isEnabled("warning")) { + if (var && var->index() + 2 < function->argCount() && _settings->isEnabled("warning")) { std::list::const_reverse_iterator it = function->argumentList.rbegin(); ++it; wrongParameterTo_va_start_error(tok, var->name(), it->name()); diff --git a/test/testvaarg.cpp b/test/testvaarg.cpp index 3ba65fc43..e830f836c 100644 --- a/test/testvaarg.cpp +++ b/test/testvaarg.cpp @@ -74,6 +74,15 @@ private: " va_end(arg_ptr);\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("int main(int argc, char *argv[]) {\n" + " long(^addthem)(const char *, ...) = ^long(const char *format, ...) {\n" + " va_list argp;\n" + " va_start(argp, format);\n" + " c = va_arg(argp, int);\n" + " };\n" + "}"); // Don't crash (#6032) + ASSERT_EQUALS("[test.cpp:6]: (error) va_list 'argp' was opened but not closed by va_end().\n", errout.str()); } void referenceAs_va_start() {