From 247145756dbfa5ff532747b93ace67ae66e1a7ff Mon Sep 17 00:00:00 2001 From: Milind Murhekar Date: Tue, 13 Nov 2018 19:00:11 +0530 Subject: [PATCH] [Fix] Use localtime_r() instead of localtime() Description: This patch fixes the DF180802-00046 issue. Change-Id: Ic2c784e4369deefc8ad74a3616c54da90b289c0f Signed-off-by: Milind Murhekar --- src/monitor/stc-time.c | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/monitor/stc-time.c b/src/monitor/stc-time.c index 1f30f96..e0f86e0 100644 --- a/src/monitor/stc-time.c +++ b/src/monitor/stc-time.c @@ -56,51 +56,52 @@ time_t stc_time_get_week_start(time_t now) time_t stc_time_get_month_start(time_t now, int month_start_date) { - struct tm *curr; + struct tm curr; + struct tm *res; bool is_leap_year; - curr = localtime(&now); + res = localtime_r(&now, &curr); - curr->tm_sec = 0; - curr->tm_min = 0; - curr->tm_hour = 0; + curr.tm_sec = 0; + curr.tm_min = 0; + curr.tm_hour = 0; - if (curr->tm_mday < month_start_date) { - curr->tm_mon--; - if (curr->tm_mon < 0) { - curr->tm_mon = 11; - curr->tm_year--; + if (curr.tm_mday < month_start_date) { + curr.tm_mon--; + if (curr.tm_mon < 0) { + curr.tm_mon = 11; + curr.tm_year--; } } - is_leap_year = ((curr->tm_year + 1900) % 4 ? 0 : 1); - curr->tm_mday = month_start_date; + is_leap_year = ((curr.tm_year + 1900) % 4 ? 0 : 1); + curr.tm_mday = month_start_date; switch (month_start_date) { case 29: case 30: - if (curr->tm_mon == 1 && !is_leap_year) - curr->tm_mday = 28; + if (curr.tm_mon == 1 && !is_leap_year) + curr.tm_mday = 28; - else if (curr->tm_mon == 1 && is_leap_year) - curr->tm_mday = 29; + else if (curr.tm_mon == 1 && is_leap_year) + curr.tm_mday = 29; break; case 31: - if (curr->tm_mon == 1 && !is_leap_year) - curr->tm_mday = 28; + if (curr.tm_mon == 1 && !is_leap_year) + curr.tm_mday = 28; - else if (curr->tm_mon == 1 && is_leap_year) - curr->tm_mday = 29; + else if (curr.tm_mon == 1 && is_leap_year) + curr.tm_mday = 29; - else if (curr->tm_mon == 3 || curr->tm_mon == 5 || - curr->tm_mon == 8 || curr->tm_mon == 10) - curr->tm_mday = 30; + else if (curr.tm_mon == 3 || curr.tm_mon == 5 || + curr.tm_mon == 8 || curr.tm_mon == 10) + curr.tm_mday = 30; break; default: ;//Do Nothing }; - return mktime(curr); + return mktime(&curr); } -- 2.7.4