more error messages when failing parsing

This commit is contained in:
iceman1001 2020-04-11 20:41:05 +02:00
parent de0768fadc
commit 309020c64c

View file

@ -38,6 +38,7 @@ int CLIParserParseArg(int argc, char **argv, void *vargtable[], size_t vargtable
if (arg_nullcheck(argtable) != 0) { if (arg_nullcheck(argtable) != 0) {
/* NULL entries were detected, some allocations must have failed */ /* NULL entries were detected, some allocations must have failed */
printf("ERROR: Insufficient memory\n"); printf("ERROR: Insufficient memory\n");
fflush(stdout);
return 2; return 2;
} }
/* Parse the command line as defined by argtable[] */ /* Parse the command line as defined by argtable[] */
@ -54,6 +55,7 @@ int CLIParserParseArg(int argc, char **argv, void *vargtable[], size_t vargtable
if (programHelp) if (programHelp)
printf("%s \n", programHelp); printf("%s \n", programHelp);
fflush(stdout);
return 1; return 1;
} }
@ -62,7 +64,7 @@ int CLIParserParseArg(int argc, char **argv, void *vargtable[], size_t vargtable
/* Display the error details contained in the arg_end struct.*/ /* Display the error details contained in the arg_end struct.*/
arg_print_errors(stdout, ((struct arg_end *)argtable[vargtableLen - 1]), programName); arg_print_errors(stdout, ((struct arg_end *)argtable[vargtableLen - 1]), programName);
printf("Try '%s --help' for more information.\n", programName); printf("Try '%s --help' for more information.\n", programName);
fflush(stdout);
return 3; return 3;
} }
@ -155,18 +157,24 @@ int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int
int ibuf = 0; int ibuf = 0;
uint8_t tmp_buf[256] = {0}; uint8_t tmp_buf[256] = {0};
int res = CLIParamStrToBuf(argstr, tmp_buf, maxdatalen * 2, &ibuf); // *2 because here HEX int res = CLIParamStrToBuf(argstr, tmp_buf, maxdatalen * 2, &ibuf); // *2 because here HEX
if (res || !ibuf) if (res || !ibuf){
printf("Parameter error: buffer overflow.\n");
fflush(stdout);
return res; return res;
}
switch (param_gethex_to_eol((char *)tmp_buf, 0, data, maxdatalen, datalen)) { switch (param_gethex_to_eol((char *)tmp_buf, 0, data, maxdatalen, datalen)) {
case 1: case 1:
printf("Parameter error: Invalid HEX value.\n"); printf("Parameter error: Invalid HEX value.\n");
fflush(stdout);
return 1; return 1;
case 2: case 2:
printf("Parameter error: parameter too large.\n"); printf("Parameter error: parameter too large.\n");
fflush(stdout);
return 2; return 2;
case 3: case 3:
printf("Parameter error: Hex string must have even number of digits.\n"); printf("Parameter error: Hex string must have even number of digits.\n");
fflush(stdout);
return 3; return 3;
} }