Skip to content

Commit de4de15

Browse files
Fix unit-tests
1 parent 60980e7 commit de4de15

File tree

5 files changed

+19
-31
lines changed

5 files changed

+19
-31
lines changed

MISRA.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ _Ref 18.2.1_
5151

5252
_Ref 14.3.1_
5353

54-
- MISRA C-2012 Rule 14.3 prohibits use of invarients in conditional statements. Since
54+
- MISRA C-2012 Rule 14.3 prohibits use of invariants in conditional statements. Since
5555
coreMQTT is designed to be compiled and executed on different machines with different
5656
architectures, it is designed to protect against overflows when converting different
5757
types to one another. In doing so, we have macros which check for such conditions on

docs/doxygen/include/size_table.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<tr>
1111
<td>core_mqtt.c</td>
1212
<td><center>8.1K</center></td>
13-
<td><center>7.0K</center></td>
13+
<td><center>7.1K</center></td>
1414
</tr>
1515
<tr>
1616
<td>core_mqtt_state.c</td>
@@ -19,8 +19,8 @@
1919
</tr>
2020
<tr>
2121
<td>core_mqtt_serializer.c</td>
22-
<td><center>9.2K</center></td>
23-
<td><center>7.4K</center></td>
22+
<td><center>9.3K</center></td>
23+
<td><center>7.5K</center></td>
2424
</tr>
2525
<tr>
2626
<td>core_mqtt_serializer_private.c</td>
@@ -30,7 +30,7 @@
3030
<tr>
3131
<td>core_mqtt_prop_serializer.c</td>
3232
<td><center>1.6K</center></td>
33-
<td><center>1.3K</center></td>
33+
<td><center>1.4K</center></td>
3434
</tr>
3535
<tr>
3636
<td>core_mqtt_prop_deserializer.c</td>
@@ -39,7 +39,7 @@
3939
</tr>
4040
<tr>
4141
<td><b>Total estimates</b></td>
42-
<td><b><center>22.7K</center></b></td>
43-
<td><b><center>18.7K</center></b></td>
42+
<td><b><center>22.8K</center></b></td>
43+
<td><b><center>19.0K</center></b></td>
4444
</tr>
4545
</table>

source/core_mqtt_serializer.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,7 +2821,7 @@ static MQTTStatus_t deserializePublishProperties( MQTTPublishInfo_t * pPublishIn
28212821
}
28222822
else
28232823
{
2824-
/* For QoS > 0, 2 byte packet ID is included. See whether the remaining length can accomodate that. */
2824+
/* For QoS > 0, 2 byte packet ID is included. See whether the remaining length can accommodate that. */
28252825
uint32_t qosEncodedLength = ( pPublishInfo->qos > MQTTQoS0 ) ? 2U : 0U;
28262826

28272827
/* Topic is encoded as 2 bytes for the length and topic string. */
@@ -4139,11 +4139,11 @@ MQTTStatus_t MQTT_SerializePublishHeader( const MQTTPublishInfo_t * pPublishInfo
41394139
* + Remaining length
41404140
* - Payload Length.
41414141
*/
4142-
uint32_t packetSizeu32 = 1U + variableLengthEncodedSize( remainingLength )
4142+
uint32_t packetSizeU32 = 1U + variableLengthEncodedSize( remainingLength )
41434143
+ remainingLength
41444144
- ( ( uint32_t ) pPublishInfo->payloadLength );
41454145

4146-
if( CHECK_U32T_OVERFLOWS_SIZE_T( packetSizeu32 ) )
4146+
if( CHECK_U32T_OVERFLOWS_SIZE_T( packetSizeU32 ) )
41474147
{
41484148
LogError( ( "Length of serialized packet will not fit in size_t variable." ) );
41494149

@@ -4153,7 +4153,7 @@ MQTTStatus_t MQTT_SerializePublishHeader( const MQTTPublishInfo_t * pPublishInfo
41534153
}
41544154
else
41554155
{
4156-
packetSize = ( size_t ) packetSizeu32;
4156+
packetSize = ( size_t ) packetSizeU32;
41574157
}
41584158
}
41594159

@@ -4591,17 +4591,6 @@ MQTTStatus_t MQTT_DeserializePublish( const MQTTPacketInfo_t * pIncomingPacket,
45914591
LogError( ( "The incoming packet length is greater than the maximum packet size." ) );
45924592
status = MQTTBadResponse;
45934593
}
4594-
else if( CHECK_SIZE_T_OVERFLOWS_16BIT( pPublishInfo->topicNameLength ) )
4595-
{
4596-
LogError( ( "Topic name length must be smaller than 65535" ) );
4597-
status = MQTTBadParameter;
4598-
}
4599-
else if( CHECK_SIZE_T_OVERFLOWS_32BIT( pPublishInfo->propertyLength ) ||
4600-
( pPublishInfo->propertyLength >= MQTT_REMAINING_LENGTH_INVALID ) )
4601-
{
4602-
LogError( ( "Property length cannot be larger than MQTT maximum 268435455." ) );
4603-
status = MQTTBadParameter;
4604-
}
46054594
else
46064595
{
46074596
status = deserializePublish( pIncomingPacket, pPacketId, pPublishInfo, propBuffer, topicAliasMax );

test/unit-test/core_mqtt_serializer_utest.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct NetworkContext
4242
uint8_t ** buffer;
4343
};
4444

45-
#define MQTT_MAX_REMAINING_LENGTH ( 268435455UL )
4645
#define MQTT_PACKET_CONNACK_REMAINING_LENGTH ( ( uint8_t ) 2U ) /**< @brief A CONNACK packet always has a "Remaining length" of 2. */
4746
#define MQTT_PACKET_CONNACK_SESSION_PRESENT_MASK ( ( uint8_t ) 0x01U ) /**< @brief The "Session Present" bit is always the lowest bit. */
4847
#define MQTT_PACKET_SIMPLE_ACK_REMAINING_LENGTH ( ( uint8_t ) 2 ) /**< @brief PUBACK, PUBREC, PUBREl, PUBCOMP, UNSUBACK Remaining length. */

test/unit-test/core_mqtt_utest.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ static MQTTStatus_t MQTT_SerializeAck_SuccessAndSetDisconnect( const MQTTFixedBu
615615
uint8_t packetType,
616616
uint16_t packetId,
617617
const MQTTPropBuilder_t * pAckProperties,
618-
MQTTSuccessFailReasonCode_t * pReasonCode,
618+
const MQTTSuccessFailReasonCode_t * pReasonCode,
619619
int numcallbacks )
620620
{
621621
( void ) numcallbacks;
@@ -634,7 +634,7 @@ static MQTTStatus_t MQTT_SerializeAck_SuccessAndSetDisconnPending( const MQTTFix
634634
uint8_t packetType,
635635
uint16_t packetId,
636636
const MQTTPropBuilder_t * pAckProperties,
637-
MQTTSuccessFailReasonCode_t * pReasonCode,
637+
const MQTTSuccessFailReasonCode_t * pReasonCode,
638638
int numcallbacks )
639639
{
640640
( void ) numcallbacks;
@@ -713,7 +713,7 @@ MQTTStatus_t MQTT_SerializeAck_StubSuccess( const MQTTFixedBuffer_t * pFixedBuff
713713
}
714714

715715
static uint8_t * MQTTV5_SerializeDisconnectFixed_cb( uint8_t * pIndex,
716-
MQTTSuccessFailReasonCode_t * pReasonCode,
716+
const MQTTSuccessFailReasonCode_t * pReasonCode,
717717
uint32_t remainingLength,
718718
int numcallbacks )
719719
{
@@ -784,7 +784,7 @@ static MQTTStatus_t MQTT_GetDisconnectPacketSize_ExpectReasonMalformed( const MQ
784784
uint32_t * pRemainingLength,
785785
uint32_t * pPacketSize,
786786
uint32_t maxPacketSize,
787-
MQTTSuccessFailReasonCode_t * pReasonCode,
787+
const MQTTSuccessFailReasonCode_t * pReasonCode,
788788
int numcallbacks )
789789
{
790790
( void ) pDisconnectProperties;
@@ -800,7 +800,7 @@ static MQTTStatus_t MQTT_GetDisconnectPacketSize_ExpectReasonMalformed( const MQ
800800
}
801801

802802
static uint8_t * serializeDisconnectFixed_cb_OneByte( uint8_t * pIndex,
803-
MQTTSuccessFailReasonCode_t * pReasonCode,
803+
const MQTTSuccessFailReasonCode_t * pReasonCode,
804804
uint32_t remainingLength,
805805
int numcallbacks )
806806
{
@@ -2518,7 +2518,7 @@ void test_MQTT_Connect_error_path()
25182518
MQTT_ValidateWillProperties_ExpectAnyArgsAndReturn( MQTTSuccess );
25192519

25202520
MQTT_ValidateConnectProperties_ExpectAnyArgsAndReturn( MQTTSuccess );
2521-
MQTT_ValidateConnectProperties_ReturnThruPtr_pPacketSizeMaxValue( &receiveMax );
2521+
MQTT_ValidateConnectProperties_ReturnThruPtr_pPacketMaxSizeValue( &receiveMax );
25222522
MQTTPropAdd_MaxPacketSize_IgnoreAndReturn( MQTTSuccess );
25232523
MQTT_GetConnectPacketSize_ExpectAnyArgsAndReturn( MQTTSuccess );
25242524
serializeConnectFixedHeader_Stub( serializeConnectFixedHeader_cb );
@@ -3504,7 +3504,7 @@ void test_MQTT_Connect_happy_path1()
35043504
willInfo.topicNameLength = 10;
35053505
MQTT_ValidateWillProperties_ExpectAnyArgsAndReturn( MQTTSuccess );
35063506
MQTT_ValidateConnectProperties_ExpectAnyArgsAndReturn( MQTTSuccess );
3507-
MQTT_ValidateConnectProperties_ReturnThruPtr_pPacketSizeMaxValue( &receiveMax );
3507+
MQTT_ValidateConnectProperties_ReturnThruPtr_pPacketMaxSizeValue( &receiveMax );
35083508
MQTT_GetConnectPacketSize_IgnoreAndReturn( MQTTSuccess );
35093509
serializeConnectFixedHeader_Stub( serializeConnectFixedHeader_cb );
35103510
MQTT_GetIncomingPacketTypeAndLength_ExpectAnyArgsAndReturn( MQTTSuccess );
@@ -10162,7 +10162,7 @@ void test_MQTT_Connect_MaxPacketSizeBiggerThanBuffer( void )
1016210162
uint32_t receiveMax = UINT32_MAX;
1016310163

1016410164
MQTT_ValidateConnectProperties_ExpectAnyArgsAndReturn( MQTTSuccess );
10165-
MQTT_ValidateConnectProperties_ReturnThruPtr_pPacketSizeMaxValue( &receiveMax );
10165+
MQTT_ValidateConnectProperties_ReturnThruPtr_pPacketMaxSizeValue( &receiveMax );
1016610166

1016710167
status = MQTT_Connect( &mqttContext, &connectInfo, NULL, timeout, &sessionPresentResult, &PropertyBuilder, NULL );
1016810168
TEST_ASSERT_EQUAL_INT( MQTTBadParameter, status );

0 commit comments

Comments
 (0)