From 11f11947b5a564272c89e72671d0dd937c748424 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 18 Mar 2000 16:54:18 +0000 Subject: [PATCH] (print_uptime): Use `buf' only if fgets succeeds. --- src/uptime.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/uptime.c b/src/uptime.c index 5a39ba649..084831fa7 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -63,14 +63,16 @@ print_uptime (int n, const STRUCT_UTMP *this) { char buf[BUFSIZ]; int res; - fgets (buf, BUFSIZ, fp); - - /* The following sscanf must use the C locale. */ - setlocale (LC_NUMERIC, "C"); - res = sscanf (buf, "%lf", &upsecs); - setlocale (LC_NUMERIC, ""); - if (res == 1) - uptime = (time_t) upsecs; + char *b = fgets (buf, BUFSIZ, fp); + if (b == buf) + { + /* The following sscanf must use the C locale. */ + setlocale (LC_NUMERIC, "C"); + res = sscanf (buf, "%lf", &upsecs); + setlocale (LC_NUMERIC, ""); + if (res == 1) + uptime = (time_t) upsecs; + } fclose (fp); } -- 2.34.1