From 4df70449fe8e97407aef9dd3f54b62660ea1dd5a Mon Sep 17 00:00:00 2001 From: George Psimenos Date: Mon, 2 Sep 2019 14:56:56 +0100 Subject: [PATCH 1/2] Replace difftime and float literals --- features/cellular/framework/AT/AT_CellularSMS.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/cellular/framework/AT/AT_CellularSMS.cpp b/features/cellular/framework/AT/AT_CellularSMS.cpp index d28f981da9..fe4031c138 100644 --- a/features/cellular/framework/AT/AT_CellularSMS.cpp +++ b/features/cellular/framework/AT/AT_CellularSMS.cpp @@ -1114,7 +1114,7 @@ int AT_CellularSMS::compare_time_strings(const char *time_string_1, const char * int retVal = -2; if (success) { - double diff = difftime(t1, t2); + time_t diff = t1 - t2; if (diff > 0) { retVal = 1; @@ -1140,7 +1140,7 @@ bool AT_CellularSMS::create_time(const char *time_string, time_t *time) &time_struct.tm_hour, &time_struct.tm_min, &time_struct.tm_sec, &sign, &gmt) == kNumberOfElements) { *time = mktime(&time_struct); // add timezone as seconds. gmt is in quarter of hours. - int x = 60 * 60 * gmt * 0.25; + int x = (60 * 60 * gmt) / 4; if (sign == '+') { *time += x; } else { From 93cebc189c03d6213bf914718f12a6b0f69199ab Mon Sep 17 00:00:00 2001 From: George Psimenos Date: Mon, 2 Sep 2019 15:48:30 +0100 Subject: [PATCH 2/2] Avoid potential overflow --- features/cellular/framework/AT/AT_CellularSMS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/cellular/framework/AT/AT_CellularSMS.cpp b/features/cellular/framework/AT/AT_CellularSMS.cpp index fe4031c138..c41d7932d5 100644 --- a/features/cellular/framework/AT/AT_CellularSMS.cpp +++ b/features/cellular/framework/AT/AT_CellularSMS.cpp @@ -1140,7 +1140,7 @@ bool AT_CellularSMS::create_time(const char *time_string, time_t *time) &time_struct.tm_hour, &time_struct.tm_min, &time_struct.tm_sec, &sign, &gmt) == kNumberOfElements) { *time = mktime(&time_struct); // add timezone as seconds. gmt is in quarter of hours. - int x = (60 * 60 * gmt) / 4; + int x = (60 / 4) * 60 * gmt; if (sign == '+') { *time += x; } else {