From ee3a0a52c80eff064946aee2e967c5f9951d045e Mon Sep 17 00:00:00 2001 From: Archit Gupta Date: Mon, 3 Jun 2024 14:57:43 -0700 Subject: [PATCH] Fix time comparison overflow --- source/core_mqtt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/core_mqtt.c b/source/core_mqtt.c index 8b72c5d17..ce119737c 100644 --- a/source/core_mqtt.c +++ b/source/core_mqtt.c @@ -866,7 +866,7 @@ static int32_t sendBuffer( MQTTContext_t * pContext, size_t bytesToSend ) { int32_t sendResult; - uint32_t timeoutMs; + uint32_t startTime; int32_t bytesSentOrError = 0; const uint8_t * pIndex = pBufferToSend; @@ -876,7 +876,7 @@ static int32_t sendBuffer( MQTTContext_t * pContext, assert( pIndex != NULL ); /* Set the timeout. */ - timeoutMs = pContext->getTime() + MQTT_SEND_TIMEOUT_MS; + startTime = pContext->getTime(); while( ( bytesSentOrError < ( int32_t ) bytesToSend ) && ( bytesSentOrError >= 0 ) ) { @@ -911,7 +911,7 @@ static int32_t sendBuffer( MQTTContext_t * pContext, } /* Check for timeout. */ - if( pContext->getTime() >= timeoutMs ) + if( calculateElapsedTime( pContext->getTime(), startTime ) >= ( MQTT_SEND_TIMEOUT_MS ) ) { LogError( ( "sendBuffer: Unable to send packet: Timed out." ) ); break;