diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index 8461bbf04..a40a79c9c 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -311,9 +311,9 @@ void CheckSizeof::sizeofVoid() sizeofDereferencedVoidPointerError(tok, tok->strAt(3)); } else if (Token::Match(tok, "%var% +|-|++|--") || Token::Match(tok, "+|-|++|-- %var%")) { // Arithmetic operations on variable of type "void*" - int index = (tok->isName()) ? 0 : 1; + const int index = (tok->isName()) ? 0 : 1; const Variable* var = tok->tokAt(index)->variable(); - if (var && Token::Match(var->typeStartToken(), "void * !!*")) { + if (var && !var->isArray() && 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 f73fb5ce1..c6b83ba55 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -647,6 +647,11 @@ private: " (foo[0]).data++;\n" "}"); ASSERT_EQUALS("[test.cpp:5]: (portability) '(foo[0]).data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str()); + + // #6050 arithmetic on void** + check("void* array[10];\n" + "void** b = array + 3;\n"); + ASSERT_EQUALS("", errout.str()); } void customStrncat() {