From cf39ece8da793c86469876ebf1340f4fa29d4f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 12 Oct 2011 19:01:44 +0200 Subject: [PATCH] Fixed #3150 (Invalid warning when pointer difference is not adjacent) --- lib/check64bit.cpp | 7 +++++++ test/test64bit.cpp | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/lib/check64bit.cpp b/lib/check64bit.cpp index a72dee915..c33f49bd7 100644 --- a/lib/check64bit.cpp +++ b/lib/check64bit.cpp @@ -62,7 +62,14 @@ void Check64BitPortability::pointerassignment() assignmentIntegerToAddressError(tok->next()); else if (isint(var1) && isaddr(var2) && !tok->tokAt(3)->isPointerCompare()) + { + // assigning address => warning + // some trivial addition => warning + if (Token::Match(tok->tokAt(4), "+ %any% !!;")) + continue; + assignmentAddressToIntegerError(tok->next()); + } } } } diff --git a/test/test64bit.cpp b/test/test64bit.cpp index 3f329992d..bfc0f7e8e 100644 --- a/test/test64bit.cpp +++ b/test/test64bit.cpp @@ -140,6 +140,12 @@ private: " int *a = x * x;\n" "}\n"); TODO_ASSERT_EQUALS("error", "", errout.str()); + + check("void foo(int *start, int *end) {\n" + " int len;\n" + " int len = end + 10 - start;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } };