Skip to content

Commit

Permalink
Revert 10.5 suppression and use ternary
Browse files Browse the repository at this point in the history
  • Loading branch information
muneebahmed10 committed Jun 12, 2020
1 parent b693010 commit 6bd8770
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 107 deletions.
10 changes: 2 additions & 8 deletions libraries/standard/mqtt/src/mqtt_lightweight.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,13 +689,8 @@ static MQTTStatus_t processPublishFlags( uint8_t publishFlags,
{
LogDebug( ( "QoS is %d.", pPublishInfo->qos ) );

/* Parse the Retain bit.
* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
pPublishInfo->retain = ( bool ) UINT8_CHECK_BIT( publishFlags, MQTT_PUBLISH_FLAG_RETAIN );
/* Parse the Retain bit. */
pPublishInfo->retain = ( UINT8_CHECK_BIT( publishFlags, MQTT_PUBLISH_FLAG_RETAIN ) ) ? true : false;

LogDebug( ( "Retain bit is %d.", pPublishInfo->retain ) );

Expand Down Expand Up @@ -1038,7 +1033,6 @@ static MQTTStatus_t deserializePublish( const MQTTPacketInfo_t * pIncomingPacket
assert( pPacketId != NULL );
assert( pPublishInfo != NULL );
pVariableHeader = pIncomingPacket->pRemainingData;

/* The flags are the lower 4 bits of the first byte in PUBLISH. */
status = processPublishFlags( ( pIncomingPacket->type & 0x0FU ), pPublishInfo );

Expand Down
114 changes: 15 additions & 99 deletions libraries/standard/mqtt/src/mqtt_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,7 @@ static bool validateTransitionPublish( MQTTPublishState_t currentState,
/* Transitions from null occur when storing a new entry into the record. */
if( opType == MQTT_RECEIVE )
{
/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
isValid = ( bool ) ( ( newState == MQTTPubAckSend ) || ( newState == MQTTPubRecSend ) );
isValid = ( ( newState == MQTTPubAckSend ) || ( newState == MQTTPubRecSend ) ) ? true : false;
}

break;
Expand All @@ -145,21 +140,11 @@ static bool validateTransitionPublish( MQTTPublishState_t currentState,
switch( qos )
{
case MQTTQoS1:
/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
isValid = ( bool ) ( newState == MQTTPubAckPending );
isValid = ( newState == MQTTPubAckPending ) ? true : false;
break;

case MQTTQoS2:
/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
isValid = ( bool ) ( newState == MQTTPubRecPending );
isValid = ( newState == MQTTPubRecPending ) ? true : false;
break;

default:
Expand Down Expand Up @@ -188,79 +173,37 @@ static bool validateTransitionAck( MQTTPublishState_t currentState,
/* Incoming publish, QoS 1. */
case MQTTPubAckPending:
/* Outgoing publish, QoS 1. */

/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
isValid = ( bool ) ( newState == MQTTPublishDone );
isValid = ( newState == MQTTPublishDone ) ? true : false;
break;

case MQTTPubRecSend:
/* Incoming publish, QoS 2. */

/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
isValid = ( bool ) ( newState == MQTTPubRelPending );
isValid = ( newState == MQTTPubRelPending ) ? true : false;
break;

case MQTTPubRelPending:
/* Incoming publish, QoS 2. */

/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
isValid = ( bool ) ( newState == MQTTPubCompSend );
isValid = ( newState == MQTTPubCompSend ) ? true : false;
break;

case MQTTPubCompSend:
/* Incoming publish, QoS 2. */

/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
isValid = ( bool ) ( newState == MQTTPublishDone );
isValid = ( newState == MQTTPublishDone ) ? true : false;
break;

case MQTTPubRecPending:
/* Outgoing publish, Qos 2. */

/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
isValid = ( bool ) ( newState == MQTTPubRelSend );
isValid = ( newState == MQTTPubRelSend ) ? true : false;
break;

case MQTTPubRelSend:
/* Outgoing publish, Qos 2. */

/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
isValid = ( bool ) ( newState == MQTTPubCompPending );
isValid = ( newState == MQTTPubCompPending ) ? true : false;
break;

case MQTTPubCompPending:
/* Outgoing publish, Qos 2. */

/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
isValid = ( bool ) ( newState == MQTTPublishDone );
isValid = ( newState == MQTTPublishDone ) ? true : false;
break;

case MQTTPublishDone:
Expand All @@ -287,21 +230,11 @@ static bool isPublishOutgoing( MQTTPubAckType_t packetType,
case MQTTPuback:
case MQTTPubrec:
case MQTTPubcomp:
/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
isOutgoing = ( bool ) ( opType == MQTT_RECEIVE );
isOutgoing = ( opType == MQTT_RECEIVE ) ? true : false;
break;

case MQTTPubrel:
/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
isOutgoing = ( bool ) ( opType == MQTT_SEND );
isOutgoing = ( opType == MQTT_SEND ) ? true : false;
break;

default:
Expand Down Expand Up @@ -554,23 +487,12 @@ MQTTPublishState_t MQTT_CalculateStateAck( MQTTPubAckType_t packetType,
{
MQTTPublishState_t calculatedState = MQTTStateNull;
/* There are more QoS2 cases than QoS1, so initialize to that. */

/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
bool qosValid = ( bool ) ( qos == MQTTQoS2 );
bool qosValid = ( qos == MQTTQoS2 ) ? true : false;

switch( packetType )
{
case MQTTPuback:
/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
qosValid = ( bool ) ( qos == MQTTQoS1 );
qosValid = ( qos == MQTTQoS1 ) ? true : false;
calculatedState = MQTTPublishDone;
break;

Expand Down Expand Up @@ -649,13 +571,7 @@ MQTTStatus_t MQTT_UpdateStateAck( MQTTContext_t * pMqttContext,
if( recordIndex < MQTT_STATE_ARRAY_MAX_COUNT )
{
newState = MQTT_CalculateStateAck( packetType, opType, qos );

/* Removing the below cast results in a MISRA 10.3 violation (required, implicit cast
* from a boolean), and keeping it results in a 10.5 violation (advisory, explicit cast).
* The violation can only be resolved if the variable is of a boolean type, which is
* not present in C89. */
/* coverity[misra_c_2012_rule_10_5_violation] */
shouldDeleteRecord = ( bool ) ( newState == MQTTPublishDone );
shouldDeleteRecord = ( newState == MQTTPublishDone ) ? true : false;
isTransitionValid = validateTransitionAck( currentState, newState );

if( isTransitionValid == true )
Expand Down

0 comments on commit 6bd8770

Please sign in to comment.