Fixed #10483 (FP constParameter with array member and memcpy)
This commit is contained in:
parent
05acc13582
commit
6234e9ddda
|
@ -1446,6 +1446,26 @@ void CheckOther::checkConstVariable()
|
|||
if (castToNonConst)
|
||||
continue;
|
||||
}
|
||||
// Do not warn if struct data is changed
|
||||
{
|
||||
bool changeStructData = false;
|
||||
for (const Token* tok = var->nameToken(); tok != scope->bodyEnd && tok != nullptr; tok = tok->next()) {
|
||||
if (tok->variable() == var && Token::Match(tok, "%var% .")) {
|
||||
const Token *parent = tok;
|
||||
while (Token::simpleMatch(parent->astParent(), ".") && parent == parent->astParent()->astOperand1())
|
||||
parent = parent->astParent();
|
||||
if (parent->valueType() &&
|
||||
parent->valueType()->pointer > 0 &&
|
||||
parent->valueType()->constness == 0 &&
|
||||
isVariableChanged(parent, 1, mSettings, mTokenizer->isCPP())) {
|
||||
changeStructData = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changeStructData)
|
||||
continue;
|
||||
}
|
||||
|
||||
constVariableError(var, function);
|
||||
}
|
||||
|
|
|
@ -2757,6 +2757,13 @@ private:
|
|||
check("class Base { virtual void dostuff(int *p) = 0; };\n" // #10397
|
||||
"class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("struct Data { char buf[128]; };\n" // #10483
|
||||
"void encrypt(Data& data) {\n"
|
||||
" const char a[] = \"asfasd\";\n"
|
||||
" memcpy(data.buf, &a, sizeof(a));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void switchRedundantAssignmentTest() {
|
||||
|
|
Loading…
Reference in New Issue