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>
This commit is contained in:
11
slabtop.c
11
slabtop.c
@@ -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*,
|
||||
|
||||
Reference in New Issue
Block a user