From: Jim Meyering Date: Sun, 14 Aug 2005 08:30:25 +0000 (+0000) Subject: (long_time_expected_width): Revert last change, just to X-Git-Tag: v5.90~397 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=006d08a85d29ab06198d406c537218b9978d888d;p=thirdparty%2Fcoreutils.git (long_time_expected_width): Revert last change, just to be paranoid, and add a comment explaining why. Paul Eggert mentioned the possibility. --- diff --git a/src/ls.c b/src/ls.c index 561d7fe526..a3d4bde711 100644 --- 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;