Fixed #10547 (False positive: constVariable, buffer written by stream read)
This commit is contained in:
parent
c49d246303
commit
921f5c1818
|
@ -1525,10 +1525,15 @@ void CheckOther::checkConstPointer()
|
||||||
if (!p->scope() || !p->scope()->function || p->scope()->function->isImplicitlyVirtual(true) || p->scope()->function->hasVirtualSpecifier())
|
if (!p->scope() || !p->scope()->function || p->scope()->function->isImplicitlyVirtual(true) || p->scope()->function->hasVirtualSpecifier())
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (nonConstPointers.find(p) == nonConstPointers.end())
|
if (nonConstPointers.find(p) == nonConstPointers.end()) {
|
||||||
|
const Token *start = (p->isArgument()) ? p->scope()->bodyStart : p->nameToken()->next();
|
||||||
|
const int indirect = p->isArray() ? p->dimensions().size() : 1;
|
||||||
|
if (isVariableChanged(start, p->scope()->bodyEnd, indirect, p->declarationId(), false, mSettings, mTokenizer->isCPP()))
|
||||||
|
continue;
|
||||||
constVariableError(p, nullptr);
|
constVariableError(p, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void CheckOther::constVariableError(const Variable *var, const Function *function)
|
void CheckOther::constVariableError(const Variable *var, const Function *function)
|
||||||
{
|
{
|
||||||
const std::string vartype((var && var->isArgument()) ? "Parameter" : "Variable");
|
const std::string vartype((var && var->isArgument()) ? "Parameter" : "Variable");
|
||||||
|
|
|
@ -2764,6 +2764,13 @@ private:
|
||||||
" memcpy(data.buf, &a, sizeof(a));\n"
|
" memcpy(data.buf, &a, sizeof(a));\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #10547
|
||||||
|
check("void foo(std::istream &istr) {\n"
|
||||||
|
" unsigned char x[2];\n"
|
||||||
|
" istr >> x[0];\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void switchRedundantAssignmentTest() {
|
void switchRedundantAssignmentTest() {
|
||||||
|
|
Loading…
Reference in New Issue