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>
This commit is contained in:
parent
c0e7e96c1a
commit
208a043256
11
tload.c
11
tload.c
@ -87,8 +87,7 @@ int main(int argc, char **argv)
|
|||||||
int lines, row, col = 0;
|
int lines, row, col = 0;
|
||||||
int i, opt;
|
int i, opt;
|
||||||
double av[3];
|
double av[3];
|
||||||
static double max_scale, scale_fact;
|
static double max_scale = 0, scale_fact;
|
||||||
char *scale_arg = NULL;
|
|
||||||
long tmpdly;
|
long tmpdly;
|
||||||
|
|
||||||
static const struct option longopts[] = {
|
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)
|
getopt_long(argc, argv, "s:d:Vh", longopts, NULL)) != -1)
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 's':
|
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;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
tmpdly = strtol_or_err(optarg, _("failed to parse argument"));
|
tmpdly = strtol_or_err(optarg, _("failed to parse argument"));
|
||||||
@ -133,9 +134,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
setsize(0);
|
setsize(0);
|
||||||
|
|
||||||
if (scale_arg)
|
if (max_scale == 0)
|
||||||
max_scale = atof(scale_arg);
|
|
||||||
else
|
|
||||||
max_scale = nrows;
|
max_scale = nrows;
|
||||||
|
|
||||||
scale_fact = max_scale;
|
scale_fact = max_scale;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user