From 762592a5cce0af41badb70dc840a6015e554baca Mon Sep 17 00:00:00 2001 From: Neel Date: Sun, 25 Jan 2026 15:06:29 -0500 Subject: [PATCH 1/4] Reliability: Compare member by member to check object equality, "DateTime" contains padding. --- lib/datetime/same.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/datetime/same.c b/lib/datetime/same.c index b23a33853c4..aed8372c44b 100644 --- a/lib/datetime/same.c +++ b/lib/datetime/same.c @@ -20,6 +20,14 @@ */ int datetime_is_same(const DateTime *src, const DateTime *dst) { - /* WARNING: doesn't allow for padding */ - return memcmp(src, dst, sizeof(DateTime)) == 0; + /* Compare field-by-field (DateTime may contain padding) */ + return src->year == dst->year && + src->month == dst->month && + src->day == dst->day && + src->hour == dst->hour && + src->minute == dst->minute && + src->second == dst->second && + src->usec == dst->usec && + src->timezone == dst->timezone; + } From bce75b42dc080b60bc0f144e46b594039df80830 Mon Sep 17 00:00:00 2001 From: Neel Date: Sun, 25 Jan 2026 15:26:22 -0500 Subject: [PATCH 2/4] Maintainabiliy: Replace this call to the non reentrant function "localtime" by a call to "localtime_r". --- lib/datetime/local.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/datetime/local.c b/lib/datetime/local.c index cdbac052f9f..f6f4d482955 100644 --- a/lib/datetime/local.c +++ b/lib/datetime/local.c @@ -27,13 +27,14 @@ */ int datetime_get_local_timezone(int *minutes) { + struct tm local_tm, gm_tm; struct tm *local, *gm; time_t clock; DateTime dtl, dtg, dtdiff; time(&clock); - local = localtime(&clock); + local = localtime_r(&clock, &local_tm); datetime_set_type(&dtl, DATETIME_ABSOLUTE, DATETIME_YEAR, DATETIME_SECOND, 0); From 2338578ab38f06d203599fc929e298c51cf4fca4 Mon Sep 17 00:00:00 2001 From: Neel Date: Sun, 25 Jan 2026 15:27:55 -0500 Subject: [PATCH 3/4] Maintainbility: Replace this call to the non reentrant function "gmtime" by a call to "gmtime_r". --- lib/datetime/local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datetime/local.c b/lib/datetime/local.c index f6f4d482955..c2f9b33bef8 100644 --- a/lib/datetime/local.c +++ b/lib/datetime/local.c @@ -47,7 +47,7 @@ int datetime_get_local_timezone(int *minutes) datetime_set_minute(&dtl, (int)local->tm_min); datetime_set_second(&dtl, (double)local->tm_sec); - gm = gmtime(&clock); + gm = gmtime_r(&clock, &gm_tm); datetime_set_type(&dtg, DATETIME_ABSOLUTE, DATETIME_YEAR, DATETIME_SECOND, 0); From 95f6a8cf5dca2f1cf595491758f2602a00b7c3a4 Mon Sep 17 00:00:00 2001 From: Neel Date: Sun, 25 Jan 2026 15:29:40 -0500 Subject: [PATCH 4/4] Maintainability: Replace this call to the non reentrant function "localtime" by a call to "localtime_r". --- lib/datetime/local.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/datetime/local.c b/lib/datetime/local.c index c2f9b33bef8..b35b3f1bfd9 100644 --- a/lib/datetime/local.c +++ b/lib/datetime/local.c @@ -81,6 +81,7 @@ int datetime_get_local_timezone(int *minutes) void datetime_get_local_time(DateTime *dt) { time_t clock; + struct tm local_tm; struct tm *local; /* first set dt to absolute full date */ @@ -88,7 +89,7 @@ void datetime_get_local_time(DateTime *dt) /* get the current date/time */ time(&clock); - local = localtime(&clock); + local = localtime_r(&clock, &local_tm); /* now put current {year,month,day,hour,minute,second} into dt */ datetime_set_year(dt, (int)local->tm_year + 1900);