@@ -2833,22 +2833,22 @@ MQTTStatus_t MQTT_Connect( MQTTContext_t * pContext,
2833
2833
pContext -> index = 0 ;
2834
2834
( void ) memset ( pContext -> networkBuffer .pBuffer , 0 , pContext -> networkBuffer .size );
2835
2835
2836
- if ( * pSessionPresent != true )
2836
+ if ( * pSessionPresent != true && pContext -> outgoingPublishRecordMaxCount > 0U )
2837
2837
{
2838
2838
/* Clear any existing records if a new session is established. */
2839
- if ( pContext -> outgoingPublishRecordMaxCount > 0U )
2840
- {
2841
- ( void ) memset ( pContext -> outgoingPublishRecords ,
2842
- 0x00 ,
2843
- pContext -> outgoingPublishRecordMaxCount * sizeof ( * pContext -> outgoingPublishRecords ) );
2844
- }
2845
-
2846
- if ( pContext -> incomingPublishRecordMaxCount > 0U )
2847
- {
2848
- ( void ) memset ( pContext -> incomingPublishRecords ,
2849
- 0x00 ,
2850
- pContext -> incomingPublishRecordMaxCount * sizeof ( * pContext -> incomingPublishRecords ) );
2851
- }
2839
+ ( void ) memset ( pContext -> outgoingPublishRecords ,
2840
+ 0x00 ,
2841
+ pContext -> outgoingPublishRecordMaxCount * sizeof ( * pContext -> outgoingPublishRecords ) );
2842
+ }
2843
+ else if ( * pSessionPresent != true && pContext -> incomingPublishRecordMaxCount > 0U )
2844
+ {
2845
+ ( void ) memset ( pContext -> incomingPublishRecords ,
2846
+ 0x00 ,
2847
+ pContext -> incomingPublishRecordMaxCount * sizeof ( * pContext -> incomingPublishRecords ) );
2848
+ }
2849
+ else
2850
+ {
2851
+ /* MISRA Empty body */
2852
2852
}
2853
2853
2854
2854
pContext -> connectStatus = MQTTConnected ;
@@ -2879,7 +2879,7 @@ MQTTStatus_t MQTT_Connect( MQTTContext_t * pContext,
2879
2879
LogInfo ( ( "MQTT Connection is either already established or a disconnect is pending, return status = %s." ,
2880
2880
MQTT_Status_strerror ( status ) ) );
2881
2881
}
2882
- else if ( status == MQTTBadParameter )
2882
+ else if ( pContext == NULL )
2883
2883
{
2884
2884
LogError ( ( "MQTT connection failed with status = %s." ,
2885
2885
MQTT_Status_strerror ( status ) ) );
0 commit comments