summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-08-14 08:30:25 +0000
committerJim Meyering <jim@meyering.net>2005-08-14 08:30:25 +0000
commit006d08a85d29ab06198d406c537218b9978d888d (patch)
tree9a7576b163821b930431eaed975dcd82d253b524 /src
parent2a372ff7dcbeb57beae8fb6dead4e7965575d5d2 (diff)
downloadcoreutils-006d08a85d29ab06198d406c537218b9978d888d.tar.xz
(long_time_expected_width): Revert last change, just to
be paranoid, and add a comment explaining why. Paul Eggert mentioned the possibility.
Diffstat (limited to 'src')
-rw-r--r--src/ls.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/ls.c b/src/ls.c
index 561d7fe52..a3d4bde71 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;