CheckSizeof: allow division with sizeof(char) when byte count is expected.

This commit is contained in:
Daniel Marjamäki 2016-07-17 19:19:05 +02:00
parent 9422f0c558
commit 0162f33d3f
1 changed files with 10 additions and 3 deletions

View File

@ -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;