]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(long_time_expected_width): Revert last change, just to
authorJim Meyering <jim@meyering.net>
Sun, 14 Aug 2005 08:30:25 +0000 (08:30 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 14 Aug 2005 08:30:25 +0000 (08:30 +0000)
be paranoid, and add a comment explaining why.
Paul Eggert mentioned the possibility.

src/ls.c

index 561d7fe526e4b7a899c9a4817917a6dd69f462c5..a3d4bde711e2b3ef3d39e06e3622f4a7270e5853 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -3068,15 +3068,20 @@ long_time_expected_width (void)
       struct tm const *tm = localtime (&epoch);
       char buf[TIME_STAMP_LEN_MAXIMUM + 1];
 
-      /* The above use of localtime cannot fail.  */
-      assert (tm != NULL);
-
-      {
-       size_t len =
-         nstrftime (buf, sizeof buf, long_time_format[0], tm, 0, 0);
-       if (len != 0)
-         width = mbsnwidth (buf, len, 0);
-      }
+      /* In case you're wondering if localtime can fail with an input time_t
+        value of 0, let's just say it's very unlikely, but not inconceivable.
+        The TZ environment variable would have to specify a time zone that
+        is 2**31-1900 years or more ahead of UTC.  This could happen only on
+        a 64-bit system that blindly accepts e.g., TZ=UTC+20000000000000.
+        However, this is not possible with Solaris 10 or glibc-2.3.5, since
+        their implementations limit the offset to 167:59 and 24:00, resp.  */
+      if (tm)
+       {
+         size_t len =
+           nstrftime (buf, sizeof buf, long_time_format[0], tm, 0, 0);
+         if (len != 0)
+           width = mbsnwidth (buf, len, 0);
+       }
 
       if (width < 0)
        width = 0;