From a4a2f78a7a4570e53e16d89b52d6d87ac2c2dee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 17 Mar 2013 17:25:57 +0100 Subject: [PATCH] Fixed #4659 (portability: address value / integer false positive) --- lib/check64bit.cpp | 2 +- test/test64bit.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/check64bit.cpp b/lib/check64bit.cpp index 78675440d..09beac543 100644 --- a/lib/check64bit.cpp +++ b/lib/check64bit.cpp @@ -68,7 +68,7 @@ void Check64BitPortability::pointerassignment() if (Token::Match(tok, "return %var%|%num% [;+]") && !Token::simpleMatch(tok, "return 0 ;")) { enum { NO, INT, PTR, PTRDIFF } type = NO; for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { - if ((type == NO || type == INT) && isaddr(tok2->variable())) + if ((type == NO || type == INT) && Token::Match(tok2, "%var% [+;]") && isaddr(tok2->variable())) type = PTR; else if (type == NO && (tok2->isNumber() || isint(tok2->variable()))) type = INT; diff --git a/test/test64bit.cpp b/test/test64bit.cpp index d408a83e7..c2eec88f2 100644 --- a/test/test64bit.cpp +++ b/test/test64bit.cpp @@ -95,6 +95,11 @@ private: " *p = 0;\n" "}\n"); ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout.str()); + + check("int f(const char *p) {\n" // #4659 + " return 6 + p[2] * 256;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void structmember() {