diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index 4c82c991e..11fe5c7bb 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -162,6 +162,9 @@ void CheckSizeof::checkSizeofForPointerSize() while (Token::Match(variable, "%var% ::|.")) variable = variable->tokAt(2); + while (Token::Match(variable2, "%var% ::|.")) + variable2 = variable2->tokAt(2); + // Ensure the variables are in the symbol database // Also ensure the variables are pointers // Only keep variables which are pointers @@ -192,9 +195,9 @@ void CheckSizeof::checkSizeofForPointerSize() // Now check for the sizeof usage: Does the level of pointer indirection match? if (tokSize->linkAt(1)->strAt(-1) == "*") { - if (variable && variable->valueType() && variable->valueType()->pointer == 1) + if (variable && variable->valueType() && variable->valueType()->pointer == 1 && variable->valueType()->type != ValueType::VOID) sizeofForPointerError(variable, variable->str()); - else if (variable2 && variable2->valueType() && variable2->valueType()->pointer == 1) + else if (variable2 && variable2->valueType() && variable2->valueType()->pointer == 1 && variable2->valueType()->type != ValueType::VOID) sizeofForPointerError(variable2, variable2->str()); } diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index 0d91f5f3c..ca6acff65 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -573,6 +573,20 @@ private: " memmove(aug + extra_string, aug, buf - (bfd_byte *)aug);\n" // #7100 "}"); ASSERT_EQUALS("", errout.str()); + + // #7518 + check("bool create_iso_definition(cpp_reader *pfile, cpp_macro *macro) {\n" + " cpp_token *token;\n" + " cpp_hashnode **params = malloc(sizeof(cpp_hashnode *) * macro->paramc);\n" + " memcpy(params, macro->params, sizeof(cpp_hashnode *) * macro->paramc);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check("void* foo() {\n" + " void* AtomName = malloc(sizeof(char *) * 34);\n" + " return AtomName;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void checkPointerSizeofStruct() {