[Fix] Use localtime_r() instead of localtime() 08/193008/1
authorMilind Murhekar <m.murhekar@samsung.com>
Tue, 13 Nov 2018 13:30:11 +0000 (19:00 +0530)
committerMilind Murhekar <m.murhekar@samsung.com>
Tue, 13 Nov 2018 13:30:11 +0000 (19:00 +0530)
Description: This patch fixes the DF180802-00046
issue.

Change-Id: Ic2c784e4369deefc8ad74a3616c54da90b289c0f
Signed-off-by: Milind Murhekar <m.murhekar@samsung.com>
src/monitor/stc-time.c

index 1f30f96..e0f86e0 100644 (file)
@@ -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);
 }