Skip to content

Commit

Permalink
Remove extra overflow check in sntpClient_GetTime function
Browse files Browse the repository at this point in the history
  • Loading branch information
kar-rahul-aws committed Apr 26, 2024
1 parent 6304fee commit 05dc808
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions FreeRTOS-Plus/Demo/coreSNTP_Windows_Simulator/SNTPClientTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ static int32_t UdpTransport_Recv( NetworkContext_t * pNetworkContext,
static void sntpClient_GetTime( SntpTimestamp_t * pCurrentTime )
{
UTCTime_t currentTime;
uint64_t ntpSecs;
uint32_t ntpSecs;

/* Obtain mutex for accessing system clock variables */
xSemaphoreTake( xMutex, portMAX_DELAY );
Expand All @@ -856,20 +856,9 @@ static void sntpClient_GetTime( SntpTimestamp_t * pCurrentTime )
xSemaphoreGive( xMutex );

/* Convert UTC time from UNIX timescale to SNTP timestamp format. */
ntpSecs = ( uint64_t ) ( currentTime.secs + SNTP_TIME_AT_UNIX_EPOCH_SECS );
ntpSecs = currentTime.secs + SNTP_TIME_AT_UNIX_EPOCH_SECS;

/* Support case of SNTP timestamp rollover on 7 February 2036 when
* converting from UNIX time to SNTP timestamp. */
if( ntpSecs > UINT32_MAX )
{
/* Subtract an extra second as timestamp 0 represents the epoch for
* NTP era 1. */
pCurrentTime->seconds = ( uint32_t ) ( ntpSecs - UINT32_MAX - 1 );
}
else
{
pCurrentTime->seconds = ( uint32_t ) ( ntpSecs );
}
pCurrentTime->seconds = ntpSecs;

pCurrentTime->fractions = MILLISECONDS_TO_SNTP_FRACTIONS( currentTime.msecs );
}
Expand Down

0 comments on commit 05dc808

Please sign in to comment.