From 223c95c95db48390a09d2460cd1533c66bc8304b Mon Sep 17 00:00:00 2001 From: Craig Small Date: Wed, 4 Jan 2012 09:53:51 +1100 Subject: [PATCH] free -c option uses strutils The handling of the -c (count) option in free uses the standard string handling and error utils. The program also checks for negative counts and errors on these. --- Makefile.am | 1 + free.c | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index aa950382..2b7c3b41 100644 --- a/Makefile.am +++ b/Makefile.am @@ -70,6 +70,7 @@ skill_SOURCES = skill.c $(top_srcdir)/lib/strutils.c snice_SOURCES = skill.c $(top_srcdir)/lib/strutils.c tload_SOURCES = tload.c $(top_srcdir)/lib/strutils.c pkill_SOURCES = pgrep.c +free_SOURCES = free.c $(top_srcdir)/lib/strutils.c vmstat_SOURCES = vmstat.c $(top_srcdir)/lib/strutils.c sysconf_DATA = sysctl.conf diff --git a/free.c b/free.c index cd1b1455..dd2d9eb7 100644 --- a/free.c +++ b/free.c @@ -12,10 +12,12 @@ * Copyright 2004 Albert Cahalan */ +#include "config.h" #include "proc/sysinfo.h" #include "proc/version.h" #include "c.h" #include "nls.h" +#include "strutils.h" #include #include @@ -255,10 +257,11 @@ int main(int argc, char **argv) case 'c': flags |= FREE_REPEAT; flags |= FREE_REPEATCOUNT; - args.repeat_counter = strtoul(optarg, &endptr, 10); - if (errno || optarg == endptr || (endptr && *endptr)) - xerrx(EXIT_FAILURE, _("count argument `%s' failed"), optarg); - + args.repeat_counter = strtol_or_err(optarg, + _("failed to parse count argument")); + if (args.repeat_counter > ULONG_MAX/2) + error(EXIT_FAILURE, ERANGE, + _("failed to parse count argument: '%s'"), optarg); break; case HELP_OPTION: usage(stdout); -- 2.40.0