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

Fix time comparison overflow #288

Merged
merged 1 commit into from
Jun 4, 2024
Merged
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
6 changes: 3 additions & 3 deletions source/core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,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 @@ -874,7 +874,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 @@ -909,7 +909,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
Loading