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.
This commit is contained in:
Varun B Patil 2013-12-18 18:26:10 +05:30
parent 5ff3a23c18
commit e69983d6de

View File

@ -394,20 +394,23 @@ int32_t main (int32_t iArgC, char* pArgV[]) {
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 @@ int32_t main (int32_t iArgC, char* pArgV[]) {
return 0;
}