CheckSizeof: allow division with sizeof(char) when byte count is expected.
This commit is contained in:
parent
9422f0c558
commit
0162f33d3f
|
@ -157,12 +157,19 @@ void CheckSizeof::checkSizeofForPointerSize()
|
||||||
|
|
||||||
if (tokFunc && tokSize) {
|
if (tokFunc && tokSize) {
|
||||||
for (const Token* tok2 = tokSize; tok2 != tokFunc->linkAt(1); tok2 = tok2->next()) {
|
for (const Token* tok2 = tokSize; tok2 != tokFunc->linkAt(1); tok2 = tok2->next()) {
|
||||||
if (tok2->str() == "sizeof")
|
if (Token::simpleMatch(tok2, "/ sizeof")) {
|
||||||
break;
|
// Allow division with sizeof(char)
|
||||||
if (Token::simpleMatch(tok2, "/ sizeof"))
|
if (Token::simpleMatch(tok2->next(), "sizeof (")) {
|
||||||
|
const Token *sztok = tok2->tokAt(2)->astOperand2();
|
||||||
|
const ValueType *vt = ((sztok != nullptr) ? sztok->valueType() : nullptr);
|
||||||
|
if (vt && vt->type == ValueType::CHAR && vt->pointer == 0)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
divideBySizeofError(tok2, tokFunc->str());
|
divideBySizeofError(tok2, tokFunc->str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!variable || !tokSize)
|
if (!variable || !tokSize)
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue