CheckIO: improved handling of functions returning pointers. Ticket: #4964
This commit is contained in:
parent
e223e13747
commit
5c3315db7a
|
@ -661,7 +661,8 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
|||
case 'G':
|
||||
specifier += *i;
|
||||
if (functionInfo && varTypeTok && (((varTypeTok->isStandardType() || functionInfo->retType) && !Token::Match(varTypeTok, "float|double")) ||
|
||||
Token::simpleMatch(varTypeTok->next(), "*") ||
|
||||
(!element && Token::simpleMatch(varTypeTok->next(), "*")) ||
|
||||
(element && !Token::simpleMatch(varTypeTok->next(), "*")) ||
|
||||
(specifier[0] == 'l' && (!varTypeTok->isLong() || varTypeTok->str() != "double")) ||
|
||||
(specifier[0] != 'l' && varTypeTok->isLong())))
|
||||
invalidPrintfArgTypeError_float(tok, numFormat, specifier);
|
||||
|
@ -781,9 +782,19 @@ bool CheckIO::getArgumentInfo(const Token * tok, const Variable **var, const Tok
|
|||
const Token *tok1 = tok->next();
|
||||
for (; tok1; tok1 = tok1->next()) {
|
||||
if (tok1->str() == "," || tok1->str() == ")") {
|
||||
if (tok1->previous()->str() == "]")
|
||||
if (tok1->previous()->str() == "]") {
|
||||
varTok = tok1->linkAt(-1)->previous();
|
||||
else if (tok1->previous()->str() == ")" && tok1->linkAt(-1)->previous()->type() == Token::eFunction) {
|
||||
if (varTok->str() == ")" && varTok->link()->previous()->type() == Token::eFunction) {
|
||||
const Function * function = varTok->link()->previous()->function();
|
||||
if (function) {
|
||||
*var = 0;
|
||||
*typeTok = function->retDef;
|
||||
*func = function;
|
||||
element = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (tok1->previous()->str() == ")" && tok1->linkAt(-1)->previous()->type() == Token::eFunction) {
|
||||
const Function * function = tok1->linkAt(-1)->previous()->function();
|
||||
if (function) {
|
||||
*var = 0;
|
||||
|
|
|
@ -1021,6 +1021,13 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("int array[10];\n"
|
||||
"int * foo() { return array; }\n"
|
||||
"void f() {\n"
|
||||
" printf(\"%f\", foo()[0]);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) %f in format string (no. 1) requires a floating point number given in the argument list.\n", errout.str());
|
||||
|
||||
}
|
||||
|
||||
void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings
|
||||
|
|
Loading…
Reference in New Issue