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

Cast variable type based on format identifier #113

Merged
merged 9 commits into from
Nov 24, 2020
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
111 changes: 56 additions & 55 deletions source/core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ static int32_t sendPacket( MQTTContext_t * pContext,

if( bytesSent < 0 )
{
LogError( ( "Transport send failed. Error code=%d.", bytesSent ) );
LogError( ( "Transport send failed. Error code=%ld.", ( long int ) bytesSent ) );
totalBytesSent = bytesSent;
sendError = true;
}
Expand All @@ -620,20 +620,20 @@ static int32_t sendPacket( MQTTContext_t * pContext,
bytesRemaining -= ( size_t ) bytesSent;
totalBytesSent += bytesSent;
pIndex += bytesSent;
LogDebug( ( "BytesSent=%d, BytesRemaining=%lu,"
" TotalBytesSent=%d.",
bytesSent,
LogDebug( ( "BytesSent=%ld, BytesRemaining=%lu,"
" TotalBytesSent=%ld.",
( long int ) bytesSent,
( unsigned long ) bytesRemaining,
totalBytesSent ) );
( long int ) totalBytesSent ) );
}
}

/* Update time of last transmission if the entire packet is successfully sent. */
if( totalBytesSent > 0 )
{
pContext->lastPacketTime = sendTime;
LogDebug( ( "Successfully sent packet at time %u.",
sendTime ) );
LogDebug( ( "Successfully sent packet at time %lu.",
( unsigned long ) sendTime ) );
}

return totalBytesSent;
Expand Down Expand Up @@ -714,8 +714,8 @@ static int32_t recvExact( const MQTTContext_t * pContext,

if( bytesRecvd < 0 )
{
LogError( ( "Network error while receiving packet: ReturnCode=%d.",
bytesRecvd ) );
LogError( ( "Network error while receiving packet: ReturnCode=%ld.",
( long int ) bytesRecvd ) );
totalBytesRecvd = bytesRecvd;
receiveError = true;
}
Expand All @@ -731,11 +731,11 @@ static int32_t recvExact( const MQTTContext_t * pContext,
bytesRemaining -= ( size_t ) bytesRecvd;
totalBytesRecvd += ( int32_t ) bytesRecvd;
pIndex += bytesRecvd;
LogDebug( ( "BytesReceived=%d, BytesRemaining=%lu, "
"TotalBytesReceived=%d.",
bytesRecvd,
LogDebug( ( "BytesReceived=%ld, BytesRemaining=%lu, "
"TotalBytesReceived=%ld.",
( long int ) bytesRecvd,
( unsigned long ) bytesRemaining,
totalBytesRecvd ) );
( long int ) totalBytesRecvd ) );
}

elapsedTimeMs = calculateElapsedTime( getTimeStampMs(), entryTimeMs );
Expand Down Expand Up @@ -784,8 +784,8 @@ static MQTTStatus_t discardPacket( const MQTTContext_t * pContext,
if( bytesReceived != ( int32_t ) bytesToReceive )
{
LogError( ( "Receive error while discarding packet."
"ReceivedBytes=%d, ExpectedBytes=%lu.",
bytesReceived,
"ReceivedBytes=%ld, ExpectedBytes=%lu.",
( long int ) bytesReceived,
( unsigned long ) bytesToReceive ) );
receiveError = true;
}
Expand All @@ -810,8 +810,8 @@ static MQTTStatus_t discardPacket( const MQTTContext_t * pContext,

if( totalBytesReceived == remainingLength )
{
LogError( ( "Dumped packet. DumpedBytes=%d.",
totalBytesReceived ) );
LogError( ( "Dumped packet. DumpedBytes=%lu.",
( unsigned long ) totalBytesReceived ) );
/* Packet dumped, so no data is available. */
status = MQTTNoDataAvailable;
}
Expand Down Expand Up @@ -851,14 +851,14 @@ static MQTTStatus_t receivePacket( const MQTTContext_t * pContext,
if( bytesReceived == ( int32_t ) bytesToReceive )
{
/* Receive successful, bytesReceived == bytesToReceive. */
LogInfo( ( "Packet received. ReceivedBytes=%d.",
bytesReceived ) );
LogInfo( ( "Packet received. ReceivedBytes=%ld.",
( long int ) bytesReceived ) );
}
else
{
LogError( ( "Packet reception failed. ReceivedBytes=%d, "
LogError( ( "Packet reception failed. ReceivedBytes=%ld, "
"ExpectedBytes=%lu.",
bytesReceived,
( long int ) bytesReceived,
( unsigned long ) bytesToReceive ) );
status = MQTTRecvFailed;
}
Expand Down Expand Up @@ -941,16 +941,15 @@ static MQTTStatus_t sendPublishAcks( MQTTContext_t * pContext,

if( status != MQTTSuccess )
{
LogError( ( "Failed to update state of publish %u.", packetId ) );
LogError( ( "Failed to update state of publish %hu.",
( unsigned short ) packetId ) );
}
}
else
{
LogError( ( "Failed to send ACK packet: PacketType=%02x, "
"SentBytes=%d, "
LogError( ( "Failed to send ACK packet: PacketType=%02x, SentBytes=%ld, "
"PacketSize=%lu.",
packetTypeByte,
bytesSent,
( unsigned int ) packetTypeByte, ( long int ) bytesSent,
MQTT_PUBLISH_ACK_PACKET_SIZE ) );
status = MQTTSendFailed;
}
Expand Down Expand Up @@ -1064,8 +1063,8 @@ static MQTTStatus_t handleIncomingPublish( MQTTContext_t * pContext,
publishRecordState = MQTT_CalculateStatePublish( MQTT_RECEIVE,
publishInfo.qos );

LogDebug( ( "Incoming publish packet with packet id %u already exists.",
packetIdentifier ) );
LogDebug( ( "Incoming publish packet with packet id %hu already exists.",
( unsigned short ) packetIdentifier ) );

if( publishInfo.dup == false )
{
Expand All @@ -1074,9 +1073,9 @@ static MQTTStatus_t handleIncomingPublish( MQTTContext_t * pContext,
}
else
{
LogError( ( "Error in updating publish state for incoming publish with packet id %u."
LogError( ( "Error in updating publish state for incoming publish with packet id %hu."
" Error is %s",
packetIdentifier,
( unsigned short ) packetIdentifier,
MQTT_Status_strerror( status ) ) );
}
}
Expand Down Expand Up @@ -1146,9 +1145,9 @@ static MQTTStatus_t handlePublishAcks( MQTTContext_t * pContext,
}
else
{
LogError( ( "Updating the state engine for packet id %u"
LogError( ( "Updating the state engine for packet id %hu"
" failed with error %s.",
packetIdentifier,
( unsigned short ) packetIdentifier,
MQTT_Status_strerror( status ) ) );
}
}
Expand Down Expand Up @@ -1197,7 +1196,8 @@ static MQTTStatus_t handleIncomingAck( MQTTContext_t * pContext,

appCallback = pContext->appCallback;

LogDebug( ( "Received packet of type %02x.", pIncomingPacket->type ) );
LogDebug( ( "Received packet of type %02x.",
( unsigned int ) pIncomingPacket->type ) );

switch( pIncomingPacket->type )
{
Expand Down Expand Up @@ -1232,7 +1232,7 @@ static MQTTStatus_t handleIncomingAck( MQTTContext_t * pContext,
default:
/* Bad response from the server. */
LogError( ( "Unexpected packet type from server: PacketType=%02x.",
pIncomingPacket->type ) );
( unsigned int ) pIncomingPacket->type ) );
status = MQTTBadResponse;
break;
}
Expand Down Expand Up @@ -1385,8 +1385,8 @@ static MQTTStatus_t sendPublish( MQTTContext_t * pContext,
}
else
{
LogDebug( ( "Sent %d bytes of PUBLISH header.",
bytesSent ) );
LogDebug( ( "Sent %ld bytes of PUBLISH header.",
( long int ) bytesSent ) );

/* Send Payload if there is one to send. It is valid for a PUBLISH
* Packet to contain a zero length payload.*/
Expand All @@ -1403,8 +1403,8 @@ static MQTTStatus_t sendPublish( MQTTContext_t * pContext,
}
else
{
LogDebug( ( "Sent %d bytes of PUBLISH payload.",
bytesSent ) );
LogDebug( ( "Sent %ld bytes of PUBLISH payload.",
( long int ) bytesSent ) );
}
}
else
Expand Down Expand Up @@ -1500,7 +1500,7 @@ static MQTTStatus_t receiveConnack( const MQTTContext_t * pContext,
{
LogError( ( "Incorrect packet type %X received while expecting"
" CONNACK(%X).",
pIncomingPacket->type,
( unsigned int ) pIncomingPacket->type,
MQTT_PACKET_TYPE_CONNACK ) );
status = MQTTBadResponse;
}
Expand Down Expand Up @@ -1636,7 +1636,7 @@ static MQTTStatus_t validatePublishParams( const MQTTContext_t * pContext,
else if( ( pPublishInfo->qos != MQTTQoS0 ) && ( packetId == 0U ) )
{
LogError( ( "Packet Id is 0 for PUBLISH with QoS=%u.",
pPublishInfo->qos ) );
( unsigned int ) pPublishInfo->qos ) );
status = MQTTBadParameter;
}
else if( ( pPublishInfo->payloadLength > 0U ) && ( pPublishInfo->pPayload == NULL ) )
Expand Down Expand Up @@ -1772,8 +1772,8 @@ MQTTStatus_t MQTT_Connect( MQTTContext_t * pContext,
}
else
{
LogDebug( ( "Sent %d bytes of CONNECT packet.",
bytesSent ) );
LogDebug( ( "Sent %ld bytes of CONNECT packet.",
( long int ) bytesSent ) );
}
}

Expand Down Expand Up @@ -1863,8 +1863,8 @@ MQTTStatus_t MQTT_Subscribe( MQTTContext_t * pContext,
}
else
{
LogDebug( ( "Sent %d bytes of SUBSCRIBE packet.",
bytesSent ) );
LogDebug( ( "Sent %ld bytes of SUBSCRIBE packet.",
( long int ) bytesSent ) );
}
}

Expand Down Expand Up @@ -1998,8 +1998,8 @@ MQTTStatus_t MQTT_Ping( MQTTContext_t * pContext )
{
pContext->pingReqSendTimeMs = pContext->lastPacketTime;
pContext->waitingForPingResp = true;
LogDebug( ( "Sent %d bytes of PINGREQ packet.",
bytesSent ) );
LogDebug( ( "Sent %ld bytes of PINGREQ packet.",
( long int ) bytesSent ) );
}
}

Expand Down Expand Up @@ -2058,8 +2058,8 @@ MQTTStatus_t MQTT_Unsubscribe( MQTTContext_t * pContext,
}
else
{
LogDebug( ( "Sent %d bytes of UNSUBSCRIBE packet.",
bytesSent ) );
LogDebug( ( "Sent %ld bytes of UNSUBSCRIBE packet.",
( long int ) bytesSent ) );
}
}

Expand Down Expand Up @@ -2108,8 +2108,8 @@ MQTTStatus_t MQTT_Disconnect( MQTTContext_t * pContext )
}
else
{
LogDebug( ( "Sent %d bytes of DISCONNECT packet.",
bytesSent ) );
LogDebug( ( "Sent %ld bytes of DISCONNECT packet.",
( long int ) bytesSent ) );
}
}

Expand Down Expand Up @@ -2274,18 +2274,18 @@ MQTTStatus_t MQTT_MatchTopic( const char * pTopicName,
if( ( pTopicName == NULL ) || ( topicNameLength == 0u ) )
{
LogError( ( "Invalid paramater: Topic name should be non-NULL and its "
"length should be > 0: TopicName=%p, TopicNameLength=%u",
"length should be > 0: TopicName=%p, TopicNameLength=%hu",
( void * ) pTopicName,
topicNameLength ) );
( unsigned short ) topicNameLength ) );

status = MQTTBadParameter;
}
else if( ( pTopicFilter == NULL ) || ( topicFilterLength == 0u ) )
{
LogError( ( "Invalid paramater: Topic filter should be non-NULL and "
"its length should be > 0: TopicName=%p, TopicFilterLength=%u",
"its length should be > 0: TopicName=%p, TopicFilterLength=%hu",
( void * ) pTopicFilter,
topicFilterLength ) );
( unsigned short ) topicFilterLength ) );
status = MQTTBadParameter;
}
else if( pIsMatch == NULL )
Expand Down Expand Up @@ -2355,7 +2355,8 @@ MQTTStatus_t MQTT_GetSubAckStatusCodes( const MQTTPacketInfo_t * pSubackPacket,
{
LogError( ( "Invalid parameter: Input packet is not a SUBACK packet: "
"ExpectedType=%02x, InputType=%02x",
MQTT_PACKET_TYPE_SUBACK, pSubackPacket->type ) );
( int ) MQTT_PACKET_TYPE_SUBACK,
( int ) pSubackPacket->type ) );
status = MQTTBadParameter;
}
else if( pSubackPacket->pRemainingData == NULL )
Expand Down
Loading