From 6ce5c152a4c76ae021303e4e877070ac7c900166 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 30 Apr 2022 20:16:52 +0000 Subject: Fix bugs in previous commit git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4335 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- generator/pamseq.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'generator') diff --git a/generator/pamseq.c b/generator/pamseq.c index 7d30bc2a..b3e7578d 100644 --- a/generator/pamseq.c +++ b/generator/pamseq.c @@ -74,7 +74,7 @@ parseOptList(bool const isSpec, for (i = 0, memberError = NULL; i < depth && !memberError; ++i) { char * endPtr; - sampleList[i] = strtoul(stringList[i], &endPtr, 10); + long const n = strtol(stringList[i], &endPtr, 10); if (strlen(stringList[i]) == 0) pm_asprintf(&memberError, "is null string"); @@ -82,9 +82,13 @@ parseOptList(bool const isSpec, pm_asprintf(&memberError, "contains non-numeric character '%c'", *endPtr); - else if (sampleList[i] > maxval) + else if (n < 0) + pm_asprintf(&memberError, "is negative"); + else if (n > maxval) pm_asprintf(&memberError, "is greater than maxval %lu", maxval); + else + sampleList[i] = n; } if (memberError) { free(sampleList); @@ -113,6 +117,21 @@ validateMinIsAtMostMax(sample * const min, +static void +validateStepIsPositive(sample * const step, + unsigned int const depth) { + + unsigned int plane; + + for (plane = 0; plane < depth; ++plane) { + if (step[plane] <= 0) + pm_error("-step for plane %u (%lu) is not positive", + plane, step[plane]); + } +} + + + static void parseCommandLine(int argc, const char ** argv, struct CmdlineInfo * const cmdlineP) { @@ -202,6 +221,9 @@ parseCommandLine(int argc, const char ** argv, if (cmdlineP->min && cmdlineP->max) validateMinIsAtMostMax(cmdlineP->min, cmdlineP->max, cmdlineP->depth); + if (cmdlineP->step) + validateStepIsPositive(cmdlineP->step, cmdlineP->depth); + if (minSpec) free(min); if (maxSpec) -- cgit 1.4.1