From: Mathieu Malaterre Date: Thu, 27 Feb 2014 10:02:46 +0000 (+0000) Subject: [trunk] improve command line parser syntax checking X-Git-Tag: version.2.0.1~4^2~188 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7c120281c7659809a783d0b1bcfd844e634b77c8;p=openjpeg [trunk] improve command line parser syntax checking --- diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 33efe757..5ed5228f 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -683,10 +683,17 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param int res_spec = 0; char *s = opj_optarg; + int ret; do { sep = 0; - sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec], + ret = sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec], ¶meters->prch_init[res_spec], &sep); + if( !(ret == 2 && sep == 0) && !(ret == 3 && sep == ',') ) + { + fprintf(stderr,"\nError: could not parse precinct dimension: '%s' %x\n", s, sep); + fprintf(stderr,"Example: -i lena.raw -o lena.j2k -c [128,128],[128,128]\n"); + return 1; + } parameters->csty |= 0x01; res_spec++; s = strpbrk(s, "]") + 2;