Fixed false positive "multiplySizeof" in TortoiseSVN

This commit is contained in:
PKEuS 2014-05-19 20:57:13 +02:00
parent 8cb1f09fc2
commit 5c566e838c
2 changed files with 5 additions and 1 deletions

View File

@ -247,6 +247,7 @@ void CheckSizeof::suspiciousSizeofCalculation()
if (!_settings->isEnabled("warning") || !_settings->inconclusive)
return;
// TODO: Use AST here. This should be possible as soon as sizeof without brackets is correctly parsed
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "sizeof (")) {
const Token* const end = tok->linkAt(1);
@ -254,7 +255,7 @@ void CheckSizeof::suspiciousSizeofCalculation()
if (end->strAt(-1) == "*" || (var && var->isPointer() && !var->isArray())) {
if (end->strAt(1) == "/")
divideSizeofError(tok);
} else if (Token::simpleMatch(end, ") * sizeof"))
} else if (Token::simpleMatch(end, ") * sizeof") && end->next()->astOperand1() == tok->next())
multiplySizeofError(tok);
}
}

View File

@ -293,6 +293,9 @@ private:
check("return sizeof(foo)*bar;");
ASSERT_EQUALS("", errout.str());
check("return (end - source) / sizeof(encode_block_type) * sizeof(encode_block_type);");
ASSERT_EQUALS("", errout.str());
}
void checkPointerSizeof() {