Fix issue 9551: Out-of-bounds in getLifetimeTokens() (#2461)
This commit is contained in:
parent
ad352838c0
commit
75de485c4d
|
@ -3199,7 +3199,11 @@ std::vector<LifetimeToken> getLifetimeTokens(const Token* tok, ValueFlow::Value:
|
||||||
int n = getArgumentPos(argvar, f);
|
int n = getArgumentPos(argvar, f);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
return std::vector<LifetimeToken> {};
|
return std::vector<LifetimeToken> {};
|
||||||
const Token* argTok = getArguments(tok->previous()).at(n);
|
std::vector<const Token*> args = getArguments(tok->previous());
|
||||||
|
// TODO: Track lifetimes of default parameters
|
||||||
|
if (n >= args.size())
|
||||||
|
return std::vector<LifetimeToken> {};
|
||||||
|
const Token* argTok = args[n];
|
||||||
lt.errorPath.emplace_back(returnTok, "Return reference.");
|
lt.errorPath.emplace_back(returnTok, "Return reference.");
|
||||||
lt.errorPath.emplace_back(tok->previous(), "Called function passing '" + argTok->str() + "'.");
|
lt.errorPath.emplace_back(tok->previous(), "Called function passing '" + argTok->str() + "'.");
|
||||||
std::vector<LifetimeToken> arglts = LifetimeToken::setInconclusive(
|
std::vector<LifetimeToken> arglts = LifetimeToken::setInconclusive(
|
||||||
|
|
|
@ -4387,6 +4387,16 @@ private:
|
||||||
" if (0 * (x > 2)) {}\n"
|
" if (0 * (x > 2)) {}\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
valueOfTok(code, "x");
|
valueOfTok(code, "x");
|
||||||
|
|
||||||
|
code = "const int& f(int, const int& y = 0);\n"
|
||||||
|
"const int& f(int, const int& y) {\n"
|
||||||
|
" return y;\n"
|
||||||
|
"}\n"
|
||||||
|
"const int& g(int x) {\n"
|
||||||
|
" const int& r = f(x);\n"
|
||||||
|
" return r;\n"
|
||||||
|
"}\n";
|
||||||
|
valueOfTok(code, "0");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue