File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -233,7 +233,8 @@ void CheckSizeof::checkSizeofForPointerSize()
233233 // Now check for the sizeof usage: Does the level of pointer indirection match?
234234 const Token * const tokLink = tokSize->linkAt (1 );
235235 if (tokLink && tokLink->strAt (-1 ) == " *" ) {
236- if (variable && variable->valueType () && variable->valueType ()->pointer == 1 && variable->valueType ()->type != ValueType::VOID)
236+ if (variable && variable->valueType () && variable->valueType ()->pointer == 1 && variable->valueType ()->type != ValueType::VOID &&
237+ variable->valueType ()->isTypeEqual (tokSize->next ()->astOperand2 ()->valueType ()))
237238 sizeofForPointerError (variable, variable->str ());
238239 else if (variable2 && variable2->valueType () && variable2->valueType ()->pointer == 1 && variable2->valueType ()->type != ValueType::VOID)
239240 sizeofForPointerError (variable2, variable2->str ());
Original file line number Diff line number Diff line change @@ -722,6 +722,12 @@ class TestSizeof : public TestFixture {
722722 " return AtomName;\n "
723723 " }" );
724724 ASSERT_EQUALS (" " , errout_str ());
725+
726+ check (" void* f(size_t n) {\n " // #11754
727+ " char* p = malloc(n * sizeof(void*));\n "
728+ " return p;\n "
729+ " }" );
730+ ASSERT_EQUALS (" " , errout_str ());
725731 }
726732
727733 void checkPointerSizeofStruct () {
You can’t perform that action at this time.
0 commit comments