From eeb147d528d7a032fc411bd4afecc3065b5f9282 Mon Sep 17 00:00:00 2001 From: Eitan Adler Date: Wed, 22 Aug 2018 09:49:38 +0000 Subject: [PATCH] top(1): issue warning on invalid delay When top -sH is run it continually updates. It should issue an warning instead. Reported by: jmg PR: 230803 --- usr.bin/top/top.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index 558491da3c3..b76dbb54676 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -253,6 +254,7 @@ main(int argc, char *argv[]) char *order_name = NULL; int order_index = 0; fd_set readfds; + char *nptr; /* set the buffer for stdout */ #ifdef DEBUG @@ -386,7 +388,12 @@ main(int argc, char *argv[]) } case 's': - delay = strtod(optarg, NULL); + delay = strtod(optarg, &nptr); + if (nptr == optarg) { + warnx("warning: invalid delay"); + delay = 2; + warnings++; + } if (delay < 0) { fprintf(stderr, "%s: warning: seconds delay should be positive -- using default\n",