Fixed #3910 (False positive: Variable is not assigned a value (pointerArray alias))
This commit is contained in:
parent
be464b43b3
commit
25b24d149f
|
@ -430,7 +430,7 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de
|
||||||
Variables::VariableUsage* var2 = variables.find(varid2);
|
Variables::VariableUsage* var2 = variables.find(varid2);
|
||||||
|
|
||||||
if (var2) { // local variable (alias or read it)
|
if (var2) { // local variable (alias or read it)
|
||||||
if (var1->_type == Variables::pointer) {
|
if (var1->_type == Variables::pointer || var1->_type == Variables::pointerArray) {
|
||||||
if (dereference)
|
if (dereference)
|
||||||
variables.read(varid2);
|
variables.read(varid2);
|
||||||
else {
|
else {
|
||||||
|
@ -439,8 +439,12 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de
|
||||||
var2->_type == Variables::pointer) {
|
var2->_type == Variables::pointer) {
|
||||||
bool replace = true;
|
bool replace = true;
|
||||||
|
|
||||||
|
// pointerArray => don't replace
|
||||||
|
if (var1->_type == Variables::pointerArray)
|
||||||
|
replace = false;
|
||||||
|
|
||||||
// check if variable declared in same scope
|
// check if variable declared in same scope
|
||||||
if (scope == var1->_scope)
|
else if (scope == var1->_scope)
|
||||||
replace = true;
|
replace = true;
|
||||||
|
|
||||||
// not in same scope as declaration
|
// not in same scope as declaration
|
||||||
|
@ -839,6 +843,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
} else if (var->_type == Variables::pointer || var->_type == Variables::reference) {
|
} else if (var->_type == Variables::pointer || var->_type == Variables::reference) {
|
||||||
variables.read(varid);
|
variables.read(varid);
|
||||||
variables.writeAliases(varid);
|
variables.writeAliases(varid);
|
||||||
|
} else if (var->_type == Variables::pointerArray) {
|
||||||
|
tok = doAssignment(variables, tok, false, scope);
|
||||||
} else
|
} else
|
||||||
variables.writeAll(varid);
|
variables.writeAll(varid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1185,6 +1185,25 @@ private:
|
||||||
" *(++ptr) = 0;\n"
|
" *(++ptr) = 0;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #3910
|
||||||
|
functionVariableUsage("int foo() {\n"
|
||||||
|
" char buf[5];\n"
|
||||||
|
" char *data[2];\n"
|
||||||
|
" data[0] = buf;\n"
|
||||||
|
" do_something(data);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
functionVariableUsage("int foo() {\n"
|
||||||
|
" char buf1[5];\n"
|
||||||
|
" char buf2[5];\n"
|
||||||
|
" char *data[2];\n"
|
||||||
|
" data[0] = buf1;\n"
|
||||||
|
" data[1] = buf2;\n"
|
||||||
|
" do_something(data);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void localvar17() { // ticket #1720
|
void localvar17() { // ticket #1720
|
||||||
|
|
Loading…
Reference in New Issue