Fixed crash in CheckVaarg::va_start_argument (#6032)

This commit is contained in:
PKEuS 2014-08-06 19:34:31 +02:00
parent b708022e97
commit 076c1bd06c
2 changed files with 10 additions and 1 deletions

View File

@ -44,7 +44,7 @@ void CheckVaarg::va_start_argument()
const Variable* var = param2->variable(); const Variable* var = param2->variable();
if (var && var->isReference()) if (var && var->isReference())
referenceAs_va_start_error(param2, var->name()); 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<Variable>::const_reverse_iterator it = function->argumentList.rbegin(); std::list<Variable>::const_reverse_iterator it = function->argumentList.rbegin();
++it; ++it;
wrongParameterTo_va_start_error(tok, var->name(), it->name()); wrongParameterTo_va_start_error(tok, var->name(), it->name());

View File

@ -74,6 +74,15 @@ private:
" va_end(arg_ptr);\n" " va_end(arg_ptr);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); 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() { void referenceAs_va_start() {