Skip to content

Commit

Permalink
Make changes for passing the coverity static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
DakshitBabbar committed Jan 28, 2025
1 parent 8dfeccb commit e1876e4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
62 changes: 31 additions & 31 deletions source/core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2208,38 +2208,39 @@ static MQTTStatus_t sendPublishWithoutCopy( MQTTContext_t * pContext,
totalMessageLength += pPublishInfo->payloadLength;
}

/* If not already set, set the dup flag before storing a copy of the publish
* this is because on retrieving back this copy we will get it in the form of an
* array of TransportOutVector_t that holds the data in a const pointer which cannot be
* changed after retrieving. */
if( pPublishInfo->dup != true )
{
MQTT_UpdateDuplicatePublishFlag( pMqttHeader, true );

dupFlagChanged = true;
}

/* store a copy of the publish for retransmission purposes */
if( ( pPublishInfo->qos > MQTTQoS0 ) &&
( pContext->storeFunction != NULL ) )
{
MQTTVec_t mqttVec;
/* If not already set, set the dup flag before storing a copy of the publish
* this is because on retrieving back this copy we will get it in the form of an
* array of TransportOutVector_t that holds the data in a const pointer which cannot be
* changed after retrieving. */
if( pPublishInfo->dup != true )
{
status = MQTT_UpdateDuplicatePublishFlag( pMqttHeader, true );

mqttVec.pVector = pIoVector;
mqttVec.vectorLen = ioVectorLength;
dupFlagChanged = ( status == MQTTSuccess );
}

if( pContext->storeFunction( pContext, packetId, &mqttVec ) != true )
if( status == MQTTSuccess )
{
status = MQTTPublishStoreFailed;
}
}
MQTTVec_t mqttVec;

/* change the value of the dup flag to its original, if it was changed */
if( dupFlagChanged )
{
MQTT_UpdateDuplicatePublishFlag( pMqttHeader, false );
mqttVec.pVector = pIoVector;
mqttVec.vectorLen = ioVectorLength;

if( pContext->storeFunction( pContext, packetId, &mqttVec ) != true )
{
status = MQTTPublishStoreFailed;
}
}

dupFlagChanged = false;
/* change the value of the dup flag to its original, if it was changed */
if( ( status == MQTTSuccess ) && ( dupFlagChanged == true ) )
{
status = MQTT_UpdateDuplicatePublishFlag( pMqttHeader, false );
}
}

if( ( status == MQTTSuccess ) &&
Expand Down Expand Up @@ -2608,8 +2609,7 @@ static MQTTStatus_t handleCleanSession( MQTTContext_t * pContext )
{
pContext->clearFunction( pContext, packetId );
}
} while( ( packetId != MQTT_PACKET_ID_INVALID ) &&
( status == MQTTSuccess ) );
} while( packetId != MQTT_PACKET_ID_INVALID );
}

if( pContext->outgoingPublishRecordMaxCount > 0U )
Expand Down Expand Up @@ -2864,7 +2864,7 @@ MQTTStatus_t MQTT_CancelCallback( const MQTTContext_t * pContext,

/*-----------------------------------------------------------*/

MQTTStatus_t MQTT_CheckConnectStatus( MQTTContext_t * pContext )
MQTTStatus_t MQTT_CheckConnectStatus( const MQTTContext_t * pContext )
{
MQTTConnectionStatus_t connectStatus;
MQTTStatus_t status = MQTTSuccess;
Expand Down Expand Up @@ -3729,11 +3729,11 @@ const char * MQTT_Status_strerror( MQTTStatus_t status )

/*-----------------------------------------------------------*/

size_t MQTT_GetBytesInMQTTVec( MQTTVec_t * pVec )
size_t MQTT_GetBytesInMQTTVec( const MQTTVec_t * pVec )
{
size_t memoryRequired = 0;
size_t i;
TransportOutVector_t * pTransportVec = pVec->pVector;
const TransportOutVector_t * pTransportVec = pVec->pVector;
size_t vecLen = pVec->vectorLen;

for( i = 0; i < vecLen; i++ )
Expand All @@ -3747,16 +3747,16 @@ size_t MQTT_GetBytesInMQTTVec( MQTTVec_t * pVec )
/*-----------------------------------------------------------*/

void MQTT_SerializeMQTTVec( uint8_t * pAllocatedMem,
MQTTVec_t * pVec )
const MQTTVec_t * pVec )
{
TransportOutVector_t * pTransportVec = pVec->pVector;
const TransportOutVector_t * pTransportVec = pVec->pVector;
const size_t vecLen = pVec->vectorLen;
size_t index = 0;
size_t i = 0;

for( i = 0; i < vecLen; i++ )
{
memcpy( &pAllocatedMem[ index ], pTransportVec[ i ].iov_base, pTransportVec[ i ].iov_len );
( void ) memcpy( &pAllocatedMem[ index ], (const uint8_t *) pTransportVec[ i ].iov_base, pTransportVec[ i ].iov_len );
index += pTransportVec[ i ].iov_len;
}
}
Expand Down
4 changes: 3 additions & 1 deletion source/core_mqtt_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2635,10 +2635,12 @@ MQTTStatus_t MQTT_UpdateDuplicatePublishFlag( uint8_t * pHeader,

if( pHeader == NULL )
{
LogError( "Header cannot be NULL" );
status = MQTTBadParameter;
}
else if( ( ( *pHeader ) & 0xF0 ) != MQTT_PACKET_TYPE_PUBLISH )
else if( ( ( *pHeader ) & 0xF0U ) != MQTT_PACKET_TYPE_PUBLISH )
{
LogError( "Header is not publish packet header" );
status = MQTTBadParameter;
}
else if( set == true )
Expand Down
6 changes: 3 additions & 3 deletions source/include/core_mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ MQTTStatus_t MQTT_InitRetransmits( MQTTContext_t * pContext,
* @endcode
*/
/* @[declare_mqtt_checkconnectstatus] */
MQTTStatus_t MQTT_CheckConnectStatus( MQTTContext_t * pContext );
MQTTStatus_t MQTT_CheckConnectStatus( const MQTTContext_t * pContext );
/* @[declare_mqtt_checkconnectstatus] */

/**
Expand Down Expand Up @@ -1235,7 +1235,7 @@ const char * MQTT_Status_strerror( MQTTStatus_t status );
* @return The bytes in the provided #MQTTVec array which can then be used to set aside memory to be used with MQTT_SerializeMQTTVec( void * pAllocatedMem, MQTTVec_t *pVec ) function.
*/
/* @[declare_mqtt_getbytesinmqttvec] */
size_t MQTT_GetBytesInMQTTVec( MQTTVec_t * pVec );
size_t MQTT_GetBytesInMQTTVec( const MQTTVec_t * pVec );
/* @[declare_mqtt_getbytesinmqttvec] */

/**
Expand All @@ -1246,7 +1246,7 @@ size_t MQTT_GetBytesInMQTTVec( MQTTVec_t * pVec );
*/
/* @[declare_mqtt_serializemqttvec] */
void MQTT_SerializeMQTTVec( uint8_t * pAllocatedMem,
MQTTVec_t * pVec );
const MQTTVec_t * pVec );
/* @[declare_mqtt_serializemqttvec] */

/* *INDENT-OFF* */
Expand Down

0 comments on commit e1876e4

Please sign in to comment.