Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/checksizeof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ void CheckSizeof::checkSizeofForPointerSize()
// Now check for the sizeof usage: Does the level of pointer indirection match?
const Token * const tokLink = tokSize->linkAt(1);
if (tokLink && tokLink->strAt(-1) == "*") {
if (variable && variable->valueType() && variable->valueType()->pointer == 1 && variable->valueType()->type != ValueType::VOID)
if (variable && variable->valueType() && variable->valueType()->pointer == 1 && variable->valueType()->type != ValueType::VOID &&
variable->valueType()->isTypeEqual(tokSize->next()->astOperand2()->valueType()))
sizeofForPointerError(variable, variable->str());
else if (variable2 && variable2->valueType() && variable2->valueType()->pointer == 1 && variable2->valueType()->type != ValueType::VOID)
sizeofForPointerError(variable2, variable2->str());
Expand Down
6 changes: 6 additions & 0 deletions test/testsizeof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,12 @@ class TestSizeof : public TestFixture {
" return AtomName;\n"
"}");
ASSERT_EQUALS("", errout_str());

check("void* f(size_t n) {\n" // #11754
" char* p = malloc(n * sizeof(void*));\n"
" return p;\n"
"}");
ASSERT_EQUALS("", errout_str());
}

void checkPointerSizeofStruct() {
Expand Down
Loading