From 208a043256b0b608d44792fc8f7c6198b05571dc Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 18 Dec 2011 15:58:48 +0100 Subject: tload: validate scale argument Earlier version crashed when negative value was provided. $ tload -s -1 Segmentation fault Signed-off-by: Sami Kerola --- tload.c | 11 +++++------ 1 file 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; -- cgit v1.2.1