diff options
author | Sami Kerola <kerolasa@iki.fi> | 2011-12-18 15:12:06 +0100 |
---|---|---|
committer | Sami Kerola <kerolasa@iki.fi> | 2011-12-20 17:30:54 +0100 |
commit | 741de935eff20c4cd283cbd42e946fa920d795b4 (patch) | |
tree | 9675fb2a2a4ec9afe51dc1070d4fea5eae0822b7 | |
parent | 032f2ed67480578b2c5c531994d39b537c16ebfd (diff) | |
download | procps-ng-741de935eff20c4cd283cbd42e946fa920d795b4.tar.gz |
slabtop: use strutils.c to validate user input
This commit fixes also peculiar behavior of
$ slabtop -d 0
which did not make sense. The fix is to disallow anything else but
positive integers, which includes zero as is is not positive (or
negative) number.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | slabtop.c | 11 |
2 files changed, 5 insertions, 7 deletions
diff --git a/Makefile.am b/Makefile.am index 00e7d57..389c192 100644 --- a/Makefile.am +++ b/Makefile.am @@ -58,6 +58,7 @@ dist_man_MANS += \ slabtop.1 \ top.1 \ watch.1 +slabtop_SOURCES = slabtop.c $(top_srcdir)/lib/strutils.c slabtop_LDADD = @NCURSES_LIBS@ top_LDADD = @NCURSES_LIBS@ watch_LDADD = @WATCH_NCURSES_LIBS@ @@ -28,6 +28,7 @@ #include "c.h" #include "nls.h" +#include "strutils.h" #include "proc/slab.h" #include "proc/version.h" @@ -297,14 +298,10 @@ int main(int argc, char *argv[]) char *end; case 'd': errno = 0; - delay = strtol(optarg, &end, 10); - if (errno || optarg == end || (end && *end)) - errx(EXIT_FAILURE, _("illegal delay `%s'"), - optarg); - if (delay < 0) + delay = strtol_or_err(optarg, _("illegal delay")); + if (delay < 1) errx(EXIT_FAILURE, - _("delay can not have a " - "negative value")); + _("delay must be positive integer")); break; case 's': sort_func = (int (*)(const struct slab_info*, |