ValueFlow: Handle string values in valueFlowSubFunction
This commit is contained in:
parent
ac59485e7e
commit
344016f7ab
|
@ -1329,9 +1329,8 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
|
||||||
// passing value(s) to function
|
// passing value(s) to function
|
||||||
if (Token::Match(tok, "[(,] %var% [,)]") && !tok->next()->values.empty())
|
if (Token::Match(tok, "[(,] %var% [,)]") && !tok->next()->values.empty())
|
||||||
argvalues = tok->next()->values;
|
argvalues = tok->next()->values;
|
||||||
else if (Token::Match(tok, "[(,] %num% [,)]") && MathLib::isInt(tok->strAt(1))) {
|
else if (Token::Match(tok, "[(,] %num%|%str% [,)]") && !tok->next()->values.empty()) {
|
||||||
argvalues.clear();
|
argvalues = tok->next()->values;
|
||||||
argvalues.push_back(ValueFlow::Value(MathLib::toLongNumber(tok->next()->str())));
|
|
||||||
} else {
|
} else {
|
||||||
// bool operator => values 1/0 are passed to function..
|
// bool operator => values 1/0 are passed to function..
|
||||||
const Token *op = tok->next();
|
const Token *op = tok->next();
|
||||||
|
@ -1364,7 +1363,8 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
|
||||||
// Get function argument, and check if parameter is passed by value
|
// Get function argument, and check if parameter is passed by value
|
||||||
const Function * const function = ftok->astOperand1()->function();
|
const Function * const function = ftok->astOperand1()->function();
|
||||||
const Variable * const arg = function ? function->getArgumentVar(argnr) : nullptr;
|
const Variable * const arg = function ? function->getArgumentVar(argnr) : nullptr;
|
||||||
if (!Token::Match(arg ? arg->typeStartToken() : nullptr, "%type% %var% ,|)"))
|
if (!Token::Match(arg ? arg->typeStartToken() : nullptr, "%type% %var% ,|)") &&
|
||||||
|
!Token::Match(arg ? arg->typeStartToken() : nullptr, "const| struct| %type% * %var% ,|)"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Function scope..
|
// Function scope..
|
||||||
|
|
|
@ -159,12 +159,21 @@ private:
|
||||||
void valueFlowString() {
|
void valueFlowString() {
|
||||||
const char *code;
|
const char *code;
|
||||||
|
|
||||||
|
// valueFlowAfterAssign
|
||||||
code = "const char * f() {\n"
|
code = "const char * f() {\n"
|
||||||
" static const char *x;\n"
|
" static const char *x;\n"
|
||||||
" if (a) x = \"123\";\n"
|
" if (a) x = \"123\";\n"
|
||||||
" return x;\n"
|
" return x;\n"
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 4, "\"123\""));
|
ASSERT_EQUALS(true, testValueOfX(code, 4, "\"123\""));
|
||||||
|
|
||||||
|
// valueFlowSubFunction
|
||||||
|
code = "void dostuff(const char *x) {\n"
|
||||||
|
" f(x);\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"void test() { dostuff(\"abc\"); }";
|
||||||
|
ASSERT_EQUALS(true, testValueOfX(code, 2, "\"abc\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowPointerAlias() {
|
void valueFlowPointerAlias() {
|
||||||
|
|
Loading…
Reference in New Issue