Fix possible out of bounds access on arguments (#1652)
* Fix possible outbounds access on arguments * Log a warning when the arguments mismatch * Format
This commit is contained in:
parent
155e4ce912
commit
797eccc203
|
@ -2980,7 +2980,18 @@ static void valueFlowLifetimeFunction(Token *tok, TokenList *tokenlist, ErrorLog
|
||||||
int n = getArgumentPos(var, f);
|
int n = getArgumentPos(var, f);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
continue;
|
continue;
|
||||||
const Token *argtok = getArguments(tok).at(n);
|
std::vector<const Token *> args = getArguments(tok);
|
||||||
|
if (n >= args.size()) {
|
||||||
|
if (tokenlist->getSettings()->debugwarnings)
|
||||||
|
bailout(tokenlist,
|
||||||
|
errorLogger,
|
||||||
|
tok,
|
||||||
|
"Argument mismatch: Function '" + tok->str() + "' returning lifetime from argument index " +
|
||||||
|
std::to_string(n) + " but only " + std::to_string(args.size()) +
|
||||||
|
" arguments are available.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const Token *argtok = args[n];
|
||||||
LifetimeStore ls{argtok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::Object};
|
LifetimeStore ls{argtok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::Object};
|
||||||
ls.errorPath = v.errorPath;
|
ls.errorPath = v.errorPath;
|
||||||
ls.errorPath.emplace_front(returnTok, "Return " + lifetimeType(returnTok, &v) + ".");
|
ls.errorPath.emplace_front(returnTok, "Return " + lifetimeType(returnTok, &v) + ".");
|
||||||
|
|
Loading…
Reference in New Issue