diff options
-rw-r--r-- | src/uptime.c | 18 |
1 files 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); } |