Skip to content

Commit

Permalink
Fix time comparison overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
archigup committed Jun 3, 2024
1 parent 238350a commit 4708e56
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions source/core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 ) )
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4708e56

Please sign in to comment.