Skip to content

Commit e40e9a3

Browse files
committed
Fix time comparison overflow
1 parent 58d626a commit e40e9a3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

source/core_mqtt.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ static int32_t sendBuffer( MQTTContext_t * pContext,
864864
size_t bytesToSend )
865865
{
866866
int32_t sendResult;
867-
uint32_t timeoutMs;
867+
uint32_t startTime;
868868
int32_t bytesSentOrError = 0;
869869
const uint8_t * pIndex = pBufferToSend;
870870

@@ -874,7 +874,7 @@ static int32_t sendBuffer( MQTTContext_t * pContext,
874874
assert( pIndex != NULL );
875875

876876
/* Set the timeout. */
877-
timeoutMs = pContext->getTime() + MQTT_SEND_TIMEOUT_MS;
877+
startTime = pContext->getTime();
878878

879879
while( ( bytesSentOrError < ( int32_t ) bytesToSend ) && ( bytesSentOrError >= 0 ) )
880880
{
@@ -909,7 +909,7 @@ static int32_t sendBuffer( MQTTContext_t * pContext,
909909
}
910910

911911
/* Check for timeout. */
912-
if( pContext->getTime() >= timeoutMs )
912+
if( calculateElapsedTime( pContext->getTime(), startTime ) >= ( MQTT_SEND_TIMEOUT_MS ) )
913913
{
914914
LogError( ( "sendBuffer: Unable to send packet: Timed out." ) );
915915
break;

0 commit comments

Comments
 (0)