Skip to content

Commit

Permalink
Remove void * from memset
Browse files Browse the repository at this point in the history
  • Loading branch information
muneebahmed10 committed Sep 18, 2020
1 parent 0281aa8 commit 92c254a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
58 changes: 29 additions & 29 deletions test/unit-test/core_mqtt_serializer_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ static void padAndResetBuffer( uint8_t * pBuffer,
}

/* Zero out rest of buffer. */
memset( ( void * ) &pBuffer[ BUFFER_PADDING_LENGTH ], 0x0, bufferLength - 2 * BUFFER_PADDING_LENGTH );
memset( &pBuffer[ BUFFER_PADDING_LENGTH ], 0x0, bufferLength - 2 * BUFFER_PADDING_LENGTH );
}

/**
Expand Down Expand Up @@ -444,7 +444,7 @@ void test_MQTT_GetConnectPacketSize( void )
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );

/* Verify empty connect info fails. */
memset( ( void * ) &connectInfo, 0x0, sizeof( connectInfo ) );
memset( &connectInfo, 0x0, sizeof( connectInfo ) );
status = MQTT_GetConnectPacketSize( &connectInfo, NULL, &remainingLength, &packetSize );
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );

Expand All @@ -460,7 +460,7 @@ void test_MQTT_GetConnectPacketSize( void )
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );

/* Test a will message payload length that is too large. */
memset( ( void * ) &connectInfo, 0x0, sizeof( connectInfo ) );
memset( &connectInfo, 0x0, sizeof( connectInfo ) );
connectInfo.pClientIdentifier = CLIENT_IDENTIFIER;
connectInfo.clientIdentifierLength = UINT16_MAX;
connectInfo.pPassword = "";
Expand All @@ -475,7 +475,7 @@ void test_MQTT_GetConnectPacketSize( void )
TEST_ASSERT_EQUAL( MQTTBadParameter, status );

/* Verify good case */
memset( ( void * ) &connectInfo, 0x0, sizeof( connectInfo ) );
memset( &connectInfo, 0x0, sizeof( connectInfo ) );
connectInfo.cleanSession = true;
connectInfo.pClientIdentifier = "TEST";
connectInfo.clientIdentifierLength = 4;
Expand All @@ -488,7 +488,7 @@ void test_MQTT_GetConnectPacketSize( void )

/* With will. These parameters will cause the packet to be
* 4 + 2 + 8 + 2 = 16 bytes larger. */
memset( ( void * ) &willInfo, 0x0, sizeof( willInfo ) );
memset( &willInfo, 0x0, sizeof( willInfo ) );
willInfo.pTopicName = "test";
willInfo.topicNameLength = 4;
willInfo.pPayload = "testload";
Expand Down Expand Up @@ -534,17 +534,17 @@ void test_MQTT_SerializeConnect( void )
status = MQTT_SerializeConnect( &connectInfo, &willInfo, remainingLength, NULL );
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );

memset( ( void * ) &connectInfo, 0x0, sizeof( connectInfo ) );
memset( &connectInfo, 0x0, sizeof( connectInfo ) );
status = MQTT_SerializeConnect( &connectInfo, NULL, 120, &fixedBuffer );
TEST_ASSERT_EQUAL_INT( MQTTNoMemory, status );

/* Create a good connection info. */
memset( ( void * ) &connectInfo, 0x0, sizeof( connectInfo ) );
memset( &connectInfo, 0x0, sizeof( connectInfo ) );
connectInfo.pClientIdentifier = "TEST";
connectInfo.clientIdentifierLength = 4;

/* Inject a invalid fixed buffer test with a good connectInfo. */
memset( ( void * ) &fixedBuffer, 0x0, sizeof( fixedBuffer ) );
memset( &fixedBuffer, 0x0, sizeof( fixedBuffer ) );
status = MQTT_SerializeConnect( &connectInfo, NULL, remainingLength, &fixedBuffer );
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );

Expand Down Expand Up @@ -685,7 +685,7 @@ void test_MQTT_GetSubscribePacketSize( void )


/* Verify empty subscription list fails. */
memset( ( void * ) &subscriptionList, 0x0, sizeof( subscriptionList ) );
memset( &subscriptionList, 0x0, sizeof( subscriptionList ) );
subscriptionCount = 0;
status = MQTT_GetSubscribePacketSize( &subscriptionList,
subscriptionCount,
Expand All @@ -711,7 +711,7 @@ void test_MQTT_GetSubscribePacketSize( void )
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );

/* Verify good case. */
memset( ( void * ) &subscriptionList, 0x0, sizeof( subscriptionList ) );
memset( &subscriptionList, 0x0, sizeof( subscriptionList ) );
subscriptionList.qos = MQTTQoS0;
subscriptionList.pTopicFilter = "/example/topic";
subscriptionList.topicFilterLength = sizeof( "/example/topic" );
Expand Down Expand Up @@ -759,7 +759,7 @@ void test_MQTT_GetUnsubscribePacketSize( void )


/* Verify empty subscription list fails. */
memset( ( void * ) &subscriptionList, 0x0, sizeof( subscriptionList ) );
memset( &subscriptionList, 0x0, sizeof( subscriptionList ) );
subscriptionCount = 0;
status = MQTT_GetUnsubscribePacketSize( &subscriptionList,
subscriptionCount,
Expand All @@ -785,7 +785,7 @@ void test_MQTT_GetUnsubscribePacketSize( void )
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );

/* Verify good case. */
memset( ( void * ) &subscriptionList, 0x0, sizeof( subscriptionList ) );
memset( &subscriptionList, 0x0, sizeof( subscriptionList ) );
subscriptionList.qos = MQTTQoS0;
subscriptionList.pTopicFilter = "/example/topic";
subscriptionList.topicFilterLength = sizeof( "/example/topic" );
Expand Down Expand Up @@ -851,7 +851,7 @@ void test_MQTT_SerializeSubscribe( void )
fixedBuffer.pBuffer = &buffer[ BUFFER_PADDING_LENGTH ];

/* Get correct values of packet size and remaining length. */
memset( ( void * ) &subscriptionList, 0x0, sizeof( subscriptionList ) );
memset( &subscriptionList, 0x0, sizeof( subscriptionList ) );
subscriptionList.qos = MQTTQoS0;
subscriptionList.pTopicFilter = "/example/topic";
subscriptionList.topicFilterLength = sizeof( "/example/topic" );
Expand Down Expand Up @@ -958,7 +958,7 @@ void test_MQTT_SerializeUnsubscribe( void )
fixedBuffer.pBuffer = &buffer[ BUFFER_PADDING_LENGTH ];

/* Get correct values of packetsize and remaining length. */
memset( ( void * ) &subscriptionList, 0x0, sizeof( subscriptionList ) );
memset( &subscriptionList, 0x0, sizeof( subscriptionList ) );
subscriptionList.qos = MQTTQoS0;
subscriptionList.pTopicFilter = "/example/topic";
subscriptionList.topicFilterLength = sizeof( "/example/topic" );
Expand Down Expand Up @@ -1035,7 +1035,7 @@ void test_MQTT_GetPublishPacketSize( void )
TEST_ASSERT_EQUAL( MQTTBadParameter, status );

/* Empty topic must fail. */
memset( ( void * ) &publishInfo, 0x00, sizeof( publishInfo ) );
memset( &publishInfo, 0x00, sizeof( publishInfo ) );
publishInfo.pTopicName = NULL;
publishInfo.topicNameLength = TEST_TOPIC_NAME_LENGTH;
status = MQTT_GetPublishPacketSize( &publishInfo, &remainingLength, &packetSize );
Expand All @@ -1047,7 +1047,7 @@ void test_MQTT_GetPublishPacketSize( void )
TEST_ASSERT_EQUAL( MQTTBadParameter, status );

/* Packet too large. */
memset( ( void * ) &publishInfo, 0x00, sizeof( publishInfo ) );
memset( &publishInfo, 0x00, sizeof( publishInfo ) );
publishInfo.pTopicName = "/test/topic";
publishInfo.topicNameLength = sizeof( "/test/topic" );
publishInfo.payloadLength = MQTT_MAX_REMAINING_LENGTH;
Expand Down Expand Up @@ -1092,7 +1092,7 @@ void test_MQTT_SerializePublish( void )
"/test/topic/name/longer/than/one/hundred/twenty/eight/characters";

/* Verify bad parameters fail. */
memset( ( void * ) &publishInfo, 0x00, sizeof( publishInfo ) );
memset( &publishInfo, 0x00, sizeof( publishInfo ) );
publishInfo.pTopicName = "/test/topic";
publishInfo.topicNameLength = sizeof( "/test/topic" );

Expand Down Expand Up @@ -1218,7 +1218,7 @@ void test_MQTT_SerializePublish( void )
publishInfo.topicNameLength = strlen( longTopic );
publishInfo.pPayload = MQTT_SAMPLE_PAYLOAD;
publishInfo.payloadLength = MQTT_SAMPLE_PAYLOAD_LEN;
memset( ( void * ) buffer, 0x00, bufferSize );
memset( buffer, 0x00, bufferSize );
/* Calculate exact packet size and remaining length. */
status = MQTT_GetPublishPacketSize( &publishInfo, &remainingLength, &packetSize );
TEST_ASSERT_EQUAL_INT( MQTTSuccess, status );
Expand All @@ -1231,7 +1231,7 @@ void test_MQTT_SerializePublish( void )
&fixedBuffer );
TEST_ASSERT_EQUAL_INT( MQTTSuccess, status );
checkBufferOverflow( buffer, sizeof( buffer ) );
memset( ( void * ) expectedPacket, 0x00, sizeof( expectedPacket ) );
memset( expectedPacket, 0x00, sizeof( expectedPacket ) );
pIterator = expectedPacket;
/* Set the flags as follows: Dup = 0x8, QoS2 = 0x4, Retain = 0x1. 8 | 4 | 1 = 0xD. */
*pIterator++ = MQTT_PACKET_TYPE_PUBLISH | 0xD;
Expand Down Expand Up @@ -1359,15 +1359,15 @@ void test_MQTT_DeserializeAck_connack( void )
uint8_t buffer[ 10 ];

/* Verify parameters */
memset( ( void * ) &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) );
memset( &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) );
mqttPacketInfo.type = MQTT_PACKET_TYPE_CONNACK;
status = MQTT_DeserializeAck( NULL, &packetIdentifier, &sessionPresent );
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );
/* Packet ID can be NULL for CONNACK, don't need to check that. */
status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, NULL );
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );

memset( ( void * ) &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) );
memset( &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) );
status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &sessionPresent );
TEST_ASSERT_EQUAL( MQTTBadParameter, status );

Expand Down Expand Up @@ -1507,7 +1507,7 @@ void test_MQTT_DeserializeAck_pingresp( void )
MQTTStatus_t status = MQTTSuccess;

/* Bad remaining length. */
( void ) memset( ( void * ) &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) );
( void ) memset( &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) );
mqttPacketInfo.type = MQTT_PACKET_TYPE_PINGRESP;
mqttPacketInfo.remainingLength = MQTT_PACKET_PINGRESP_REMAINING_LENGTH + 1;
status = MQTT_DeserializeAck( &mqttPacketInfo, &packetIdentifier, &sessionPresent );
Expand All @@ -1533,7 +1533,7 @@ void test_MQTT_DeserializeAck_puback( void )
uint8_t buffer[ 10 ] = { 0 };

/* Verify parameters */
memset( ( void * ) &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) );
memset( &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) );
mqttPacketInfo.type = MQTT_PACKET_TYPE_PUBACK;
status = MQTT_DeserializeAck( NULL, &packetIdentifier, &sessionPresent );
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );
Expand Down Expand Up @@ -1605,7 +1605,7 @@ void test_MQTT_DeserializePublish( void )

const uint16_t PACKET_ID = 1;

memset( ( void * ) &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) );
memset( &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) );

/* Verify parameters. */
status = MQTT_DeserializePublish( NULL, &packetIdentifier, &publishInfo );
Expand Down Expand Up @@ -1684,7 +1684,7 @@ void test_MQTT_DeserializePublish( void )
TEST_ASSERT_EQUAL_INT( MQTT_SAMPLE_PAYLOAD_LEN, publishInfo.payloadLength );
TEST_ASSERT_EQUAL_MEMORY( MQTT_SAMPLE_PAYLOAD, publishInfo.pPayload, MQTT_SAMPLE_PAYLOAD_LEN );

memset( ( void * ) &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) );
memset( &mqttPacketInfo, 0x00, sizeof( mqttPacketInfo ) );
/* Reset publish info since its pointers now point to our serialized buffer. */
setupPublishInfo( &publishInfo );

Expand Down Expand Up @@ -1888,7 +1888,7 @@ void test_MQTT_SerializePublishHeader( void )
const uint16_t PACKET_ID = 1;

/* Verify bad parameters fail. */
memset( ( void * ) &publishInfo, 0x00, sizeof( publishInfo ) );
memset( &publishInfo, 0x00, sizeof( publishInfo ) );
publishInfo.pTopicName = TEST_TOPIC_NAME;
publishInfo.topicNameLength = TEST_TOPIC_NAME_LENGTH;
status = MQTT_SerializePublishHeader( NULL,
Expand Down Expand Up @@ -1994,7 +1994,7 @@ void test_MQTT_SerializePublishHeader( void )
* Topic name (variable)
* Packet ID (if QoS > 0) (1 byte)
* Payload (>= 0 bytes) */
memset( ( void * ) expectedPacket, 0x00, sizeof( expectedPacket ) );
memset( expectedPacket, 0x00, sizeof( expectedPacket ) );
pIterator = expectedPacket;
*pIterator++ = MQTT_PACKET_TYPE_PUBLISH | ( publishInfo.qos << 1 );
pIterator += encodeRemainingLength( pIterator, remainingLength );
Expand All @@ -2016,7 +2016,7 @@ void test_MQTT_SerializePublishHeader( void )
&fixedBuffer,
&headerSize );
TEST_ASSERT_EQUAL_INT( MQTTSuccess, status );
memset( ( void * ) expectedPacket, 0x00, sizeof( expectedPacket ) );
memset( expectedPacket, 0x00, sizeof( expectedPacket ) );
pIterator = expectedPacket;
*pIterator++ = MQTT_PACKET_TYPE_PUBLISH;
pIterator += encodeRemainingLength( pIterator, remainingLength );
Expand All @@ -2039,7 +2039,7 @@ void test_MQTT_SerializePublishHeader( void )
&headerSize );
TEST_ASSERT_EQUAL_INT( MQTTSuccess, status );

memset( ( void * ) expectedPacket, 0x00, sizeof( expectedPacket ) );
memset( expectedPacket, 0x00, sizeof( expectedPacket ) );
pIterator = expectedPacket;
/* Set the flags as follows: Dup = 0x8, QoS2 = 0x4, 8 | 4 = 0xC. */
*pIterator++ = MQTT_PACKET_TYPE_PUBLISH | 0xC;
Expand Down
28 changes: 14 additions & 14 deletions test/unit-test/core_mqtt_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static bool isEventCallbackInvoked = false;
/* Called before each test method. */
void setUp()
{
memset( ( void * ) mqttBuffer, 0x0, sizeof( mqttBuffer ) );
memset( mqttBuffer, 0x0, sizeof( mqttBuffer ) );
MQTT_State_strerror_IgnoreAndReturn( "DUMMY_MQTT_STATE" );

globalEntryTime = 0;
Expand Down Expand Up @@ -619,7 +619,7 @@ void test_MQTT_Connect_sendConnect( void )
setupTransportInterface( &transport );
setupNetworkBuffer( &networkBuffer );

memset( ( void * ) &mqttContext, 0x0, sizeof( mqttContext ) );
memset( &mqttContext, 0x0, sizeof( mqttContext ) );
MQTT_Init( &mqttContext, &transport, getTime, eventCallback, &networkBuffer );

/* Check parameters */
Expand All @@ -632,7 +632,7 @@ void test_MQTT_Connect_sendConnect( void )

/* Empty connect info fails. */
MQTT_GetConnectPacketSize_ExpectAnyArgsAndReturn( MQTTBadParameter );
memset( ( void * ) &connectInfo, 0x0, sizeof( connectInfo ) );
memset( &connectInfo, 0x0, sizeof( connectInfo ) );
status = MQTT_Connect( &mqttContext, &connectInfo, NULL, timeout, &sessionPresent );
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );

Expand Down Expand Up @@ -693,7 +693,7 @@ void test_MQTT_Connect_receiveConnack( void )
setupNetworkBuffer( &networkBuffer );
transport.recv = transportRecvFailure;

memset( ( void * ) &mqttContext, 0x0, sizeof( mqttContext ) );
memset( &mqttContext, 0x0, sizeof( mqttContext ) );
MQTT_Init( &mqttContext, &transport, getTime, eventCallback, &networkBuffer );

/* Everything before receiving the CONNACK should succeed. */
Expand Down Expand Up @@ -764,7 +764,7 @@ void test_MQTT_Connect_receiveConnack_retries( void )
setupNetworkBuffer( &networkBuffer );
transport.recv = transportRecvFailure;

memset( ( void * ) &mqttContext, 0x0, sizeof( mqttContext ) );
memset( &mqttContext, 0x0, sizeof( mqttContext ) );
MQTT_Init( &mqttContext, &transport, getTime, eventCallback, &networkBuffer );

/* Everything before receiving the CONNACK should succeed. */
Expand Down Expand Up @@ -824,7 +824,7 @@ void test_MQTT_Connect_partial_receive()
setupNetworkBuffer( &networkBuffer );
transport.recv = transportRecvOneByte;

memset( ( void * ) &mqttContext, 0x0, sizeof( mqttContext ) );
memset( &mqttContext, 0x0, sizeof( mqttContext ) );
MQTT_Init( &mqttContext, &transport, getTime, eventCallback, &networkBuffer );

/* Everything before receiving the CONNACK should succeed. */
Expand Down Expand Up @@ -898,8 +898,8 @@ void test_MQTT_Connect_resendPendingAcks( void )
setupTransportInterface( &transport );
setupNetworkBuffer( &networkBuffer );

memset( ( void * ) &mqttContext, 0x0, sizeof( mqttContext ) );
memset( ( void * ) &connectInfo, 0x00, sizeof( connectInfo ) );
memset( &mqttContext, 0x0, sizeof( mqttContext ) );
memset( &connectInfo, 0x00, sizeof( connectInfo ) );
MQTT_Init( &mqttContext, &transport, getTime, eventCallback, &networkBuffer );

MQTT_SerializeConnect_IgnoreAndReturn( MQTTSuccess );
Expand Down Expand Up @@ -1030,7 +1030,7 @@ void test_MQTT_Connect_happy_path()
setupTransportInterface( &transport );
setupNetworkBuffer( &networkBuffer );

memset( ( void * ) &mqttContext, 0x0, sizeof( mqttContext ) );
memset( &mqttContext, 0x0, sizeof( mqttContext ) );
MQTT_Init( &mqttContext, &transport, getTime, eventCallback, &networkBuffer );
connectInfo.keepAliveSeconds = MQTT_SAMPLE_KEEPALIVE_INTERVAL_S;

Expand Down Expand Up @@ -1161,8 +1161,8 @@ void test_MQTT_Publish( void )
setupNetworkBuffer( &networkBuffer );
transport.send = transportSendFailure;

memset( ( void * ) &mqttContext, 0x0, sizeof( mqttContext ) );
memset( ( void * ) &publishInfo, 0x0, sizeof( publishInfo ) );
memset( &mqttContext, 0x0, sizeof( mqttContext ) );
memset( &publishInfo, 0x0, sizeof( publishInfo ) );
MQTT_Init( &mqttContext, &transport, getTime, eventCallback, &networkBuffer );

/* Verify parameters. */
Expand All @@ -1177,7 +1177,7 @@ void test_MQTT_Publish( void )
publishInfo.pPayload = NULL;
status = MQTT_Publish( &mqttContext, &publishInfo, PACKET_ID );
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );
memset( ( void * ) &publishInfo, 0x0, sizeof( publishInfo ) );
memset( &publishInfo, 0x0, sizeof( publishInfo ) );

/* Bad Parameter when getting packet size. */
publishInfo.qos = MQTTQoS0;
Expand Down Expand Up @@ -1301,7 +1301,7 @@ void test_MQTT_Disconnect( void )
transport.recv = transportRecvSuccess;
transport.send = transportSendFailure;

memset( ( void * ) &mqttContext, 0x0, sizeof( mqttContext ) );
memset( &mqttContext, 0x0, sizeof( mqttContext ) );
MQTT_Init( &mqttContext, &transport, getTime, eventCallback, &networkBuffer );
mqttContext.connectStatus = MQTTConnected;

Expand Down Expand Up @@ -1343,7 +1343,7 @@ void test_MQTT_GetPacketId( void )

setupTransportInterface( &transport );
setupNetworkBuffer( &networkBuffer );
memset( ( void * ) &mqttContext, 0x0, sizeof( mqttContext ) );
memset( &mqttContext, 0x0, sizeof( mqttContext ) );
MQTT_Init( &mqttContext, &transport, getTime, eventCallback, &networkBuffer );

/* Verify parameters. */
Expand Down

0 comments on commit 92c254a

Please sign in to comment.