diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2022-04-30 20:16:52 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2022-04-30 20:16:52 +0000 |
commit | 6ce5c152a4c76ae021303e4e877070ac7c900166 (patch) | |
tree | e7c211e5d2e7ec3575546c68c5adb8b47584a3c8 /generator | |
parent | a0121702ba47031fd7f50de2c65ca674d416fd74 (diff) | |
download | netpbm-mirror-6ce5c152a4c76ae021303e4e877070ac7c900166.tar.gz netpbm-mirror-6ce5c152a4c76ae021303e4e877070ac7c900166.tar.xz netpbm-mirror-6ce5c152a4c76ae021303e4e877070ac7c900166.zip |
Fix bugs in previous commit
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4335 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'generator')
-rw-r--r-- | generator/pamseq.c | 26 |
1 files changed, 24 insertions, 2 deletions
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); @@ -114,6 +118,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) |