From: Jim Meyering Date: Sat, 18 Mar 2000 16:54:18 +0000 (+0000) Subject: (print_uptime): Use `buf' only if fgets succeeds. X-Git-Tag: SH-UTILS-2_0g~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=11f11947b5a564272c89e72671d0dd937c748424;p=platform%2Fupstream%2Fcoreutils.git (print_uptime): Use `buf' only if fgets succeeds. --- 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); }