ref: e69983d6de4290b3d322d6d3410cb861ccdb4863
parent: 5ff3a23c1854de399c0788d0b2e5708ce04699ad
author: Varun B Patil <varun.basavaraj.patil@gmail.com>
date: Wed Dec 18 13:26:10 EST 2013
Improve command line arguments handling in dec testapp Problems fixed: 1. No longer segfaults if an option is specified without an accompanying argument. 2. Wrongly incrementing i by 3 instead of by 2 while parsing command line options.
--- a/codec/console/dec/src/h264dec.cpp
+++ b/codec/console/dec/src/h264dec.cpp
@@ -394,20 +394,23 @@
sDecParam.uiEcActiveFlag = 1;
sDecParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
if (iArgC > 3) {
- // Basic option parser. Note that this is not safe about the
- // number of remaining arguments.
- // TODO: rewrite
for (int i = 3; i < iArgC; i++) {
char* cmd = pArgV[i];
if (!strcmp (cmd, "-options")) {
- strOptionFile = pArgV[i + 1];
- i += 2;
+ if (i + 1 < iArgC)
+ strOptionFile = pArgV[i++];
+ else {
+ printf ("options file not specified.\n");
+ return 1;
+ }
} else if (!strcmp (cmd, "-trace")) {
- WelsStderrSetTraceLevel (atoi (pArgV[i + 1]));
- i += 2;
- } else {
- i++;
+ if (i + 1 < iArgC)
+ WelsStderrSetTraceLevel (atoi (pArgV[i++]));
+ else {
+ printf ("trace level not specified.\n");
+ return 1;
+ }
}
}
}
@@ -491,4 +494,3 @@
return 0;
}
-