]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Don't dump core if localtime returns NULL (possible on
authorJim Meyering <jim@meyering.net>
Thu, 5 Feb 2004 09:51:49 +0000 (09:51 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 5 Feb 2004 09:51:49 +0000 (09:51 +0000)
hosts with 64-bit time_t and 32-bit int).

Print "??" if the current clock can't
be converted by localtime.  This won't happen until the year
2*31 + 1900, but we don't want to dump core even if the current
clock has the wrong value.

src/uptime.c

index 652b256e87e794ff0b3b37b3d6c2bea8e19838fd..3c746f57b24a63387af4fd68bf801f9bcb2d0a8b 100644 (file)
@@ -132,11 +132,14 @@ print_uptime (int n, const STRUCT_UTMP *this)
   uphours = (uptime - (updays * 86400)) / 3600;
   upmins = (uptime - (updays * 86400) - (uphours * 3600)) / 60;
   tmn = localtime (&time_now);
-  printf (_(" %2d:%02d%s  up "), ((tmn->tm_hour % 12) == 0
-                                 ? 12 : tmn->tm_hour % 12),
-         /* FIXME: use strftime, not am, pm.  Uli reports that
-            the german translation is meaningless.  */
-         tmn->tm_min, (tmn->tm_hour < 12 ? _("am") : _("pm")));
+  if (tmn)
+    printf (_(" %2d:%02d%s  up "),
+           ((tmn->tm_hour % 12) == 0 ? 12 : tmn->tm_hour % 12),
+           /* FIXME: use strftime, not am, pm.  Uli reports that
+              the german translation is meaningless.  */
+           tmn->tm_min, (tmn->tm_hour < 12 ? _("am") : _("pm")));
+  else
+    printf (_(" ??:????  up "));
   if (updays > 0)
     printf (ngettext("%d day", "%d days", updays), updays);
   printf (" %2d:%02d,  ", uphours, upmins);