From aa0560fe3b22613e7c99c03c0a136557f574719a Mon Sep 17 00:00:00 2001 From: Carlo Marcelo Arenas Belon Date: Tue, 23 Jul 2013 08:19:20 -0700 Subject: [PATCH] Fixed #4925 (False positive: checkother style) When using a variable that is assigned a function pointer checks for pointers are triggered which would complain if used in arithmetic comparisions (eventhough it will be valid code if the function returns an int) --- lib/checkother.cpp | 2 +- test/testother.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index e1ec50c1e..a9be46436 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3217,7 +3217,7 @@ void CheckOther::checkSignOfUnsignedVariable() const Variable *var = tok->tokAt(2)->variable(); if (var && var->typeEndToken()->isUnsigned()) unsignedLessThanZeroError(tok, var->name(), inconclusive); - else if (var && var->isPointer() && !Token::Match(tok->tokAt(3), "[.[]")) + else if (var && var->isPointer() && !Token::Match(tok->tokAt(3), "[.[(]")) pointerLessThanZeroError(tok, inconclusive); } else if (Token::Match(tok, "0 <= %var%") && tok->tokAt(2)->varId() && !Token::Match(tok->tokAt(3), "+|-|*|/") && !Token::Match(tok->previous(), "+|-|<<|>>|~")) { const Variable *var = tok->tokAt(2)->variable(); diff --git a/test/testother.cpp b/test/testother.cpp index e89001c42..310620d29 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4949,6 +4949,22 @@ private: " bar();\n" "}"); ASSERT_EQUALS("", errout.str()); + + check_signOfUnsignedVariable( + "void foo() {\n" + " int (*t)(void *a, void *b);\n" + " if (t(a, b) < 0)\n" + " bar();\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check_signOfUnsignedVariable( + "void foo() {\n" + " int (*t)(void *a, void *b);\n" + " if (0 > t(a, b))\n" + " bar();\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void checkForSuspiciousSemicolon1() {