Fixed false positives in CheckSizeof::checkSizeofForPointerSize() (#7518)

This commit is contained in:
PKEuS 2016-05-26 21:25:29 +02:00
parent 373ac52480
commit 00e4f70fe3
2 changed files with 19 additions and 2 deletions

View File

@ -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());
}

View File

@ -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() {