]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
utils: Printf() defined time output should gmtime/localtime_r() fail
authorMartin Willi <martin@revosec.ch>
Tue, 15 Oct 2013 14:10:05 +0000 (16:10 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 4 Jun 2014 13:52:58 +0000 (15:52 +0200)
src/libstrongswan/utils/utils.c

index 7cca845f7365b7f349b436a1adeb7d2a701cc0b4..fe3b32f6c329bc1a13cbdee33c78110fec43a692 100644 (file)
@@ -648,20 +648,23 @@ int time_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
        };
        time_t *time = *((time_t**)(args[0]));
        bool utc = *((int*)(args[1]));
-       struct tm t;
+       struct tm t, *ret = NULL;
 
-       if (*time == UNDEFINED_TIME)
+       if (*time != UNDEFINED_TIME)
        {
-               return print_in_hook(data, "--- -- --:--:--%s----",
-                                                        utc ? " UTC " : " ");
-       }
-       if (utc)
-       {
-               gmtime_r(time, &t);
+               if (utc)
+               {
+                       ret = gmtime_r(time, &t);
+               }
+               else
+               {
+                       ret = localtime_r(time, &t);
+               }
        }
-       else
+       if (ret == NULL)
        {
-               localtime_r(time, &t);
+               return print_in_hook(data, "--- -- --:--:--%s----",
+                                                        utc ? " UTC " : " ");
        }
        return print_in_hook(data, "%s %02d %02d:%02d:%02d%s%04d",
                                                 months[t.tm_mon], t.tm_mday, t.tm_hour, t.tm_min,