summaryrefslogtreecommitdiff
path: root/src/who.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-06-20 06:53:05 +0000
committerJim Meyering <jim@meyering.net>2004-06-20 06:53:05 +0000
commitf2d779e87c20bc37c3e60194c3a5c1f0f3f7c1f4 (patch)
tree9c926ed1ef4844ca0264af40f42a491c77e666cd /src/who.c
parentb3a6653a609e837bcb0a166256fba70ee8b91133 (diff)
downloadcoreutils-f2d779e87c20bc37c3e60194c3a5c1f0f3f7c1f4.tar.xz
Don't dump core if ctime returns NULL; this is possible on
hosts with 64-bit time_t and 32-bit int. Include "inttostr.h". (time_string): If ctime fails, print the raw time as an integer instead of dumping core.
Diffstat (limited to 'src/who.c')
-rw-r--r--src/who.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/who.c b/src/who.c
index 554ae1656..6dd1203e6 100644
--- a/src/who.c
+++ b/src/who.c
@@ -33,6 +33,7 @@
#include "readutmp.h"
#include "error.h"
+#include "inttostr.h"
#include "vasprintf.h"
/* The official name of this program (e.g., no `g' prefix). */
@@ -233,8 +234,17 @@ time_string (const STRUCT_UTMP *utmp_ent)
the tv_sec member of a struct timeval value.'' */
time_t tm = UT_TIME_MEMBER (utmp_ent);
- char *ptr = ctime (&tm) + 4;
- ptr[12] = '\0';
+ char *ptr = ctime (&tm);
+ if (ptr)
+ {
+ ptr += 4;
+ ptr[12] = '\0';
+ }
+ else
+ {
+ static char buf[INT_BUFSIZE_BOUND (intmax_t)];
+ ptr = (TYPE_SIGNED (time_t) ? imaxtostr (tm, buf) : umaxtostr (tm, buf));
+ }
return ptr;
}