Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnessesary ternarys #211

Merged
merged 3 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions source/core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,8 @@ static bool matchEndWildcardsSpecialCases( const char * pTopicFilter,
( pTopicFilter[ filterIndex ] == '/' ) )
{
/* Check that the last character is a wildcard. */
matchFound = ( ( pTopicFilter[ filterIndex + 1U ] == '+' ) ||
( pTopicFilter[ filterIndex + 1U ] == '#' ) ) ? true : false;
matchFound = ( pTopicFilter[ filterIndex + 1U ] == '+' ) ||
( pTopicFilter[ filterIndex + 1U ] == '#' );
}

return matchFound;
Expand Down Expand Up @@ -611,9 +611,8 @@ static bool matchWildcards( const char * pTopicName,

/* Wild card in a topic filter is only valid either at the starting position
* or when it is preceded by a '/'.*/
locationIsValidForWildcard = ( ( *pFilterIndex == 0u ) ||
( pTopicFilter[ *pFilterIndex - 1U ] == '/' )
) ? true : false;
locationIsValidForWildcard = ( *pFilterIndex == 0u ) ||
( pTopicFilter[ *pFilterIndex - 1U ] == '/' );

if( ( pTopicFilter[ *pFilterIndex ] == '+' ) && ( locationIsValidForWildcard == true ) )
{
Expand Down Expand Up @@ -752,8 +751,8 @@ static bool matchTopicFilter( const char * pTopicName,
* case when the topic filter contains the '+' wildcard at a non-starting position.
* For example, when matching either of "sport/+/player" OR "sport/hockey/+" topic
* filters with "sport/hockey/player" topic name. */
matchFound = ( ( nameIndex == topicNameLength ) &&
( filterIndex == topicFilterLength ) ) ? true : false;
matchFound = ( nameIndex == topicNameLength ) &&
( filterIndex == topicFilterLength );
}

return matchFound;
Expand Down Expand Up @@ -1617,7 +1616,7 @@ static MQTTStatus_t handleIncomingAck( MQTTContext_t * pContext,

case MQTT_PACKET_TYPE_PINGRESP:
status = MQTT_DeserializeAck( pIncomingPacket, &packetIdentifier, NULL );
invokeAppCallback = ( ( status == MQTTSuccess ) && ( manageKeepAlive == false ) ) ? true : false;
invokeAppCallback = ( status == MQTTSuccess ) && !manageKeepAlive;

if( ( status == MQTTSuccess ) && ( manageKeepAlive == true ) )
{
Expand All @@ -1630,7 +1629,7 @@ static MQTTStatus_t handleIncomingAck( MQTTContext_t * pContext,
case MQTT_PACKET_TYPE_UNSUBACK:
/* Deserialize and give these to the app provided callback. */
status = MQTT_DeserializeAck( pIncomingPacket, &packetIdentifier, NULL );
invokeAppCallback = ( ( status == MQTTSuccess ) || ( status == MQTTServerRefused ) ) ? true : false;
invokeAppCallback = ( status == MQTTSuccess ) || ( status == MQTTServerRefused );
break;

default:
Expand Down Expand Up @@ -2238,11 +2237,11 @@ static MQTTStatus_t receiveConnack( const MQTTContext_t * pContext,
* A value of 0 for the config will try once to read CONNACK. */
if( timeoutMs > 0U )
{
breakFromLoop = ( calculateElapsedTime( getTimeStamp(), entryTimeMs ) >= timeoutMs ) ? true : false;
breakFromLoop = calculateElapsedTime( getTimeStamp(), entryTimeMs ) >= timeoutMs;
}
else
{
breakFromLoop = ( loopCount >= MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT ) ? true : false;
breakFromLoop = loopCount >= MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT;
loopCount++;
}

Expand Down Expand Up @@ -3099,7 +3098,7 @@ MQTTStatus_t MQTT_MatchTopic( const char * pTopicName,
* topic filter length match. */
if( topicNameLength == topicFilterLength )
{
matchStatus = ( strncmp( pTopicName, pTopicFilter, topicNameLength ) == 0 ) ? true : false;
matchStatus = strncmp( pTopicName, pTopicFilter, topicNameLength ) == 0;
}

if( matchStatus == false )
Expand All @@ -3108,8 +3107,8 @@ MQTTStatus_t MQTT_MatchTopic( const char * pTopicName,
* topic filter.*/

/* Determine if topic filter starts with a wildcard. */
topicFilterStartsWithWildcard = ( ( pTopicFilter[ 0 ] == '+' ) ||
( pTopicFilter[ 0 ] == '#' ) ) ? true : false;
topicFilterStartsWithWildcard = ( pTopicFilter[ 0 ] == '+' ) ||
( pTopicFilter[ 0 ] == '#' );

/* Note: According to the MQTT 3.1.1 specification, incoming PUBLISH topic names
* starting with "$" character cannot be matched against topic filter starting with
Expand Down
4 changes: 2 additions & 2 deletions source/core_mqtt_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,12 +1033,12 @@ static MQTTStatus_t processPublishFlags( uint8_t publishFlags,
LogDebug( ( "QoS is %d.", ( int ) pPublishInfo->qos ) );

/* Parse the Retain bit. */
pPublishInfo->retain = ( UINT8_CHECK_BIT( publishFlags, MQTT_PUBLISH_FLAG_RETAIN ) ) ? true : false;
pPublishInfo->retain = UINT8_CHECK_BIT( publishFlags, MQTT_PUBLISH_FLAG_RETAIN );

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

/* Parse the DUP bit. */
pPublishInfo->dup = ( UINT8_CHECK_BIT( publishFlags, MQTT_PUBLISH_FLAG_DUP ) ) ? true : false;
pPublishInfo->dup = UINT8_CHECK_BIT( publishFlags, MQTT_PUBLISH_FLAG_DUP );

LogDebug( ( "DUP bit is %d.", ( int ) pPublishInfo->dup ) );
}
Expand Down
42 changes: 21 additions & 21 deletions source/core_mqtt_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static bool validateTransitionPublish( MQTTPublishState_t currentState,
/* Transitions from null occur when storing a new entry into the record. */
if( opType == MQTT_RECEIVE )
{
isValid = ( ( newState == MQTTPubAckSend ) || ( newState == MQTTPubRecSend ) ) ? true : false;
isValid = ( newState == MQTTPubAckSend ) || ( newState == MQTTPubRecSend );
}

break;
Expand All @@ -251,11 +251,11 @@ static bool validateTransitionPublish( MQTTPublishState_t currentState,
switch( qos )
{
case MQTTQoS1:
isValid = ( newState == MQTTPubAckPending ) ? true : false;
isValid = newState == MQTTPubAckPending;
break;

case MQTTQoS2:
isValid = ( newState == MQTTPubRecPending ) ? true : false;
isValid = newState == MQTTPubRecPending;
break;

case MQTTQoS0:
Expand All @@ -272,15 +272,15 @@ static bool validateTransitionPublish( MQTTPublishState_t currentState,

/* When a session is reestablished, outgoing QoS1 publishes in state
* #MQTTPubAckPending can be resent. The state remains the same. */
isValid = ( newState == MQTTPubAckPending ) ? true : false;
isValid = newState == MQTTPubAckPending;

break;

case MQTTPubRecPending:

/* When a session is reestablished, outgoing QoS2 publishes in state
* #MQTTPubRecPending can be resent. The state remains the same. */
isValid = ( newState == MQTTPubRecPending ) ? true : false;
isValid = newState == MQTTPubRecPending;

break;

Expand Down Expand Up @@ -312,12 +312,12 @@ static bool validateTransitionAck( MQTTPublishState_t currentState,
/* Incoming publish, QoS 1. */
case MQTTPubAckPending:
/* Outgoing publish, QoS 1. */
isValid = ( newState == MQTTPublishDone ) ? true : false;
isValid = newState == MQTTPublishDone;
break;

case MQTTPubRecSend:
/* Incoming publish, QoS 2. */
isValid = ( newState == MQTTPubRelPending ) ? true : false;
isValid = newState == MQTTPubRelPending;
break;

case MQTTPubRelPending:
Expand All @@ -339,8 +339,8 @@ static bool validateTransitionAck( MQTTPublishState_t currentState,
* MQTTPubRelPending.
* 7. Sending out a PUBREC will result in this transition
* to the same state. */
isValid = ( ( newState == MQTTPubCompSend ) ||
( newState == MQTTPubRelPending ) ) ? true : false;
isValid = ( newState == MQTTPubCompSend ) ||
( newState == MQTTPubRelPending );
break;

case MQTTPubCompSend:
Expand All @@ -359,18 +359,18 @@ static bool validateTransitionAck( MQTTPublishState_t currentState,
* 3. MQTT broker resent the un-acked PUBREL.
* 4. Receiving the PUBREL again will result in this transition
* to the same state. */
isValid = ( ( newState == MQTTPublishDone ) ||
( newState == MQTTPubCompSend ) ) ? true : false;
isValid = ( newState == MQTTPublishDone ) ||
( newState == MQTTPubCompSend );
break;

case MQTTPubRecPending:
/* Outgoing publish, Qos 2. */
isValid = ( newState == MQTTPubRelSend ) ? true : false;
isValid = newState == MQTTPubRelSend;
break;

case MQTTPubRelSend:
/* Outgoing publish, Qos 2. */
isValid = ( newState == MQTTPubCompPending ) ? true : false;
isValid = newState == MQTTPubCompPending;
break;

case MQTTPubCompPending:
Expand All @@ -390,8 +390,8 @@ static bool validateTransitionAck( MQTTPublishState_t currentState,
* 2. An MQTT session is reestablished.
* 3. Resending the un-acked PUBREL results in this transition
* to the same state. */
isValid = ( ( newState == MQTTPublishDone ) ||
( newState == MQTTPubCompPending ) ) ? true : false;
isValid = ( newState == MQTTPublishDone ) ||
( newState == MQTTPubCompPending );
break;

case MQTTPublishDone:
Expand Down Expand Up @@ -420,11 +420,11 @@ static bool isPublishOutgoing( MQTTPubAckType_t packetType,
case MQTTPuback:
case MQTTPubrec:
case MQTTPubcomp:
isOutgoing = ( opType == MQTT_RECEIVE ) ? true : false;
isOutgoing = opType == MQTT_RECEIVE;
break;

case MQTTPubrel:
isOutgoing = ( opType == MQTT_SEND ) ? true : false;
isOutgoing = opType == MQTT_SEND;
break;

default:
Expand Down Expand Up @@ -631,7 +631,7 @@ static uint16_t stateSelect( const MQTTContext_t * pMqttContext,
while( *pCursor < maxCount )
{
/* Check if any of the search states are present. */
stateCheck = UINT16_CHECK_BIT( searchStates, records[ *pCursor ].publishState ) ? true : false;
stateCheck = UINT16_CHECK_BIT( searchStates, records[ *pCursor ].publishState );

if( stateCheck == true )
{
Expand All @@ -654,12 +654,12 @@ MQTTPublishState_t MQTT_CalculateStateAck( MQTTPubAckType_t packetType,
{
MQTTPublishState_t calculatedState = MQTTStateNull;
/* There are more QoS2 cases than QoS1, so initialize to that. */
bool qosValid = ( qos == MQTTQoS2 ) ? true : false;
bool qosValid = qos == MQTTQoS2;

switch( packetType )
{
case MQTTPuback:
qosValid = ( qos == MQTTQoS1 ) ? true : false;
qosValid = qos == MQTTQoS1;
calculatedState = MQTTPublishDone;
break;

Expand Down Expand Up @@ -714,7 +714,7 @@ static MQTTStatus_t updateStateAck( MQTTPubAckInfo_t * records,
* is received for an outgoing QoS2 publish. When a PUBREC is received,
* record is deleted and added back to the end of the records to maintain
* ordering for PUBRELs. */
shouldDeleteRecord = ( ( newState == MQTTPublishDone ) || ( newState == MQTTPubRelSend ) ) ? true : false;
shouldDeleteRecord = ( newState == MQTTPublishDone ) || ( newState == MQTTPubRelSend );
isTransitionValid = validateTransitionAck( currentState, newState );

if( isTransitionValid == true )
Expand Down