summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Kerola <kerolasa@iki.fi>2011-12-18 15:58:48 +0100
committerSami Kerola <kerolasa@iki.fi>2011-12-20 17:30:54 +0100
commit208a043256b0b608d44792fc8f7c6198b05571dc (patch)
tree984b3036982f27e2e9b53957b92164d6c14085c6
parentc0e7e96c1a5a223905c69962fc14239aa3a1126e (diff)
downloadprocps-ng-208a043256b0b608d44792fc8f7c6198b05571dc.tar.gz
tload: validate scale argument
Earlier version crashed when negative value was provided. $ tload -s -1 Segmentation fault Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rw-r--r--tload.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/tload.c b/tload.c
index 861375d..4fe57ad 100644
--- a/tload.c
+++ b/tload.c
@@ -87,8 +87,7 @@ int main(int argc, char **argv)
int lines, row, col = 0;
int i, opt;
double av[3];
- static double max_scale, scale_fact;
- char *scale_arg = NULL;
+ static double max_scale = 0, scale_fact;
long tmpdly;
static const struct option longopts[] = {
@@ -107,7 +106,9 @@ int main(int argc, char **argv)
getopt_long(argc, argv, "s:d:Vh", longopts, NULL)) != -1)
switch (opt) {
case 's':
- scale_arg = optarg;
+ max_scale = strtod_or_err(optarg, _("failed to parse argument"));
+ if (max_scale < 0)
+ errx(EXIT_FAILURE, _("scale cannot be negative"));
break;
case 'd':
tmpdly = strtol_or_err(optarg, _("failed to parse argument"));
@@ -133,9 +134,7 @@ int main(int argc, char **argv)
setsize(0);
- if (scale_arg)
- max_scale = atof(scale_arg);
- else
+ if (max_scale == 0)
max_scale = nrows;
scale_fact = max_scale;