From 14787cde992698c91bbc06f46d7fd8d1cdff5d6b Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Thu, 31 Oct 2013 06:04:51 +0100 Subject: [PATCH] Fixed #5129 (FP:arithOperationsOnVoidPointer on void**) --- lib/checksizeof.cpp | 2 +- test/testsizeof.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index 24225a163..3f903fbb5 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -297,7 +297,7 @@ void CheckSizeof::sizeofVoid() Token::Match(tok, "+|-|++|-- %var%")) { // Arithmetic operations on variable of type "void*" int index = (tok->isName()) ? 0 : 1; const Variable* var = tok->tokAt(index)->variable(); - if (var && Token::Match(var->typeStartToken(), "void *")) { + if (var && Token::Match(var->typeStartToken(), "void * !!*")) { std::string varname = tok->strAt(index); // In case this 'void *' var is a member then go back to the main object const Token* tok2 = tok->tokAt(index); diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index 9f8b4f0eb..42acb4aaa 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -520,6 +520,12 @@ private: ASSERT_EQUALS("[test.cpp:4]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n" "[test.cpp:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str()); + check("void f() {\n" + " void** p1 = malloc(10);\n" + " p1--;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void f() {\n" " void** p1;\n" " int j = sizeof(*p1);\n"