From 57a0fda5da8295b88d94d74f94ff6f80f268e00a Mon Sep 17 00:00:00 2001 From: Kamil Sroka Date: Wed, 16 Jan 2019 09:17:32 +0100 Subject: [PATCH] [sntp] fix Keil build with SNTP_CLIENT=1 (#3460) --- include/openthread/platform/toolchain.h | 11 +++++++++++ src/core/net/sntp_client.cpp | 4 ++-- src/core/net/sntp_client.hpp | 1 - 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/openthread/platform/toolchain.h b/include/openthread/platform/toolchain.h index c892b9e74..474221349 100644 --- a/include/openthread/platform/toolchain.h +++ b/include/openthread/platform/toolchain.h @@ -300,6 +300,17 @@ extern "C" { #endif +/* + * Keil and IAR compiler doesn't provide type limits for C++. + */ +#if defined(__CC_ARM) || defined(__ICCARM__) + +#ifndef UINT32_MAX +#define UINT32_MAX 0xffffffff +#endif + +#endif + /** * @} * diff --git a/src/core/net/sntp_client.cpp b/src/core/net/sntp_client.cpp index 575472179..efd3d5785 100644 --- a/src/core/net/sntp_client.cpp +++ b/src/core/net/sntp_client.cpp @@ -365,7 +365,7 @@ void Client::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag // Due to NTP protocol limitation, this module stops working correctly after around year 2106, if // unix era is not updated. This seems to be a reasonable limitation for now. Era number cannot be // obtained using NTP protocol, and client of this module is responsible to set it properly. - unixTime = GetUnixEra() * (UINT32_MAX + 1); + unixTime = GetUnixEra() * (UINT32_MAX + 1ULL); if (responseHeader.GetTransmitTimestampSeconds() > kTimeAt1970) { @@ -374,7 +374,7 @@ void Client::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag else { unixTime += - static_cast(responseHeader.GetTransmitTimestampSeconds()) + (UINT32_MAX + 1) - kTimeAt1970; + static_cast(responseHeader.GetTransmitTimestampSeconds()) + (UINT32_MAX + 1ULL) - kTimeAt1970; } // Return the time since 1970. diff --git a/src/core/net/sntp_client.hpp b/src/core/net/sntp_client.hpp index ccef720aa..eb135ea5e 100644 --- a/src/core/net/sntp_client.hpp +++ b/src/core/net/sntp_client.hpp @@ -31,7 +31,6 @@ #include "openthread-core-config.h" -#include #include #include "common/message.hpp"