Second fix for #4207 (Internal error. Token::Match called with varid 0)

This commit is contained in:
Daniel Marjamäki 2012-09-23 13:25:28 +02:00
parent c1d4a81795
commit ec01cc811e
2 changed files with 16 additions and 3 deletions

View File

@ -605,8 +605,10 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
if (!parameter || _tokenizer->sizeOfType(parameter->typeStartToken()) != arrayInfo.element_size())
return;
// Variable function arguments..
if (Token::simpleMatch(parameter->typeStartToken(), ". . ."))
// No variable id occur for instance when:
// - Variable function arguments: "void f(...)"
// - Unnamed parameter: "void f(char *)"
if (parameter->varId() == 0)
return;
// Check the parameter usage in the function scope..

View File

@ -1453,7 +1453,8 @@ private:
ASSERT_EQUALS("", errout.str());
}
void array_index_45() { // #4207 - handling of function with variable number of parameters
void array_index_45() { // #4207 - handling of function with variable number of parameters / unnamed arguments
// Variable number of arguments
check("void f(const char *format, ...) {\n"
" va_args args;\n"
" va_start(args, format);\n"
@ -1463,6 +1464,16 @@ private:
" f(\"%s\", buffer);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// Unnamed argument
check("void f(char *) {\n"
" dostuff();\n"
"}\n"
"void test() {\n"
" char buffer[1024];\n"
" f(buffer);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void array_index_multidim() {