From: Milind Murhekar Date: Wed, 14 Nov 2018 08:59:45 +0000 (+0530) Subject: Use localtime_r() instead of localtime() X-Git-Tag: accepted/tizen/5.0/unified/20181122.060304~1^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fconnectivity%2Fstc-manager.git;a=commitdiff_plain;h=07972a99da894e2c278f87cd9d8e3019cf92b739 Use localtime_r() instead of localtime() This patch fixes the SVACE issue for locatime() usage without thread safety. Change-Id: Icc67ba1f949847b2ee5c903a1035e9ede6e764e2 Signed-off-by: Milind Murhekar --- diff --git a/src/monitor/stc-time.c b/src/monitor/stc-time.c index 750b43d..e0f86e0 100644 --- a/src/monitor/stc-time.c +++ b/src/monitor/stc-time.c @@ -22,83 +22,86 @@ time_t stc_time_get_day_start(time_t now) { - struct tm *curr; + struct tm curr; + struct tm *res; - 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; - return mktime(curr); + return mktime(&curr); } time_t stc_time_get_week_start(time_t now) { - struct tm *curr; + struct tm curr; + struct tm *res; int days; - 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_wday > 1) - days = curr->tm_wday - 1; + if (curr.tm_wday > 1) + days = curr.tm_wday - 1; else - days = 1 - curr->tm_wday; + days = 1 - curr.tm_wday; - return (mktime(curr) - (days * SEC_IN_DAY)); + return (mktime(&curr) - (days * SEC_IN_DAY)); } 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); }