This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: WEBENCH® Design Tools
In function "processAfRegisterReq", when allocate buffer for both "pAppInClusterList " and "pAppOutClusterList ", if the number of cluster is 0, 0-size malloc erro will be triggered. It can be fixed like this
if( pItem->epDesc.simpleDesc->AppNumInClusters ) //avoid 0-size malloc,add by luoyiming 2019-10-15 { pItem->epDesc.simpleDesc->pAppInClusterList = (cId_t *)OsalPort_malloc( sizeof(cId_t) * pItem->epDesc.simpleDesc->AppNumInClusters ); if ( pItem->epDesc.simpleDesc->pAppInClusterList ) { for ( i = 0; i < pItem->epDesc.simpleDesc->AppNumInClusters; i++ ) { pItem->epDesc.simpleDesc->pAppInClusterList[i] = pPtr->pReq->pSimpleDesc->pInputClusters[i]; } } } if( pItem->epDesc.simpleDesc->AppNumOutClusters ) //avoid 0-size malloc,add by luoyiming 2019-10-15 { pItem->epDesc.simpleDesc->pAppOutClusterList = (cId_t *)OsalPort_malloc( sizeof(cId_t) * pItem->epDesc.simpleDesc->AppNumOutClusters ); if ( pItem->epDesc.simpleDesc->pAppOutClusterList ) { for ( i = 0; i < pItem->epDesc.simpleDesc->AppNumOutClusters; i++ ) { pItem->epDesc.simpleDesc->pAppOutClusterList[i] = pPtr->pReq->pSimpleDesc->pOutputClusters[i]; } } } }
I have found that many many function has this issue, so I show a perfect solution, fix function "OsalPort_malloc " like this
void* OsalPort_malloc(uint32_t size) { if( !size ) { return NULL; } return (OsalPort_heapMalloc(size)); }
If HEAPMGR_ASSERT is set to assert when 0 is passed into malloc, this implementation is technically not correct because malloc(0) is allowed: https://stackoverflow.com/questions/1073157/zero-size-malloc
In the Z-Stack examples, pApp[In/Out]ClusterList is set to NULL if AppNum[In/Out]Clusters is zero.
Regards,
Ryan
I have passed this information along to the Software Development Team.
Regards,
Ryan