]> granicus.if.org Git - openjpeg/commitdiff
[trunk] improve command line parser syntax checking
authorMathieu Malaterre <mathieu.malaterre@gmail.com>
Thu, 27 Feb 2014 10:02:46 +0000 (10:02 +0000)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>
Thu, 27 Feb 2014 10:02:46 +0000 (10:02 +0000)
src/bin/jp2/opj_compress.c

index 33efe7574eac3263993e9c0ed0bf7413fd294e3b..5ed5228f1eff899e578169db3d16b38833803493 100644 (file)
@@ -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", &parameters->prcw_init[res_spec],
+                ret = sscanf(s, "[%d,%d]%c", &parameters->prcw_init[res_spec],
                        &parameters->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;