From 5c566e838c24a8a5210bce9b5690d3150cd68122 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 19 May 2014 20:57:13 +0200 Subject: [PATCH] Fixed false positive "multiplySizeof" in TortoiseSVN --- lib/checksizeof.cpp | 3 ++- test/testsizeof.cpp | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index 4427b19ae..9b74fb1f9 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -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); } } diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index 167dfa1bb..7fddeee64 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -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() {