flash/at91samd: use COMMAND_PARSE_NUMBER in command handlers

the usage of COMMAND_PARSE_NUMBER is safer in COMMAND_HANDLERs since it provides
better error checking than strto** functions.

Change-Id: I14061cb48da6bac13f9d2896190136f5784b8c07
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6424
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Tarek BOCHKATI 2021-07-29 23:47:07 +01:00 committed by Antonio Borneo
parent 277b0a5d97
commit dd0ee1fa5b
1 changed files with 4 additions and 31 deletions

View File

@ -1051,31 +1051,6 @@ COMMAND_HANDLER(samd_handle_eeprom_command)
return res;
}
static COMMAND_HELPER(get_u64_from_hexarg, unsigned int num, uint64_t *value)
{
if (num >= CMD_ARGC) {
command_print(CMD, "Too few Arguments.");
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (strlen(CMD_ARGV[num]) >= 3 &&
CMD_ARGV[num][0] == '0' &&
CMD_ARGV[num][1] == 'x') {
char *check = NULL;
*value = strtoull(&(CMD_ARGV[num][2]), &check, 16);
if ((value == 0 && errno == ERANGE) ||
!check || *check != 0) {
command_print(CMD, "Invalid 64-bit hex value in argument %d.",
num + 1);
return ERROR_COMMAND_SYNTAX_ERROR;
}
} else {
command_print(CMD, "Argument %d needs to be a hex value.", num + 1);
return ERROR_COMMAND_SYNTAX_ERROR;
}
return ERROR_OK;
}
COMMAND_HANDLER(samd_handle_nvmuserrow_command)
{
int res = ERROR_OK;
@ -1102,14 +1077,12 @@ COMMAND_HANDLER(samd_handle_nvmuserrow_command)
mask &= NVMUSERROW_LOCKBIT_MASK;
uint64_t value;
res = CALL_COMMAND_HANDLER(get_u64_from_hexarg, 0, &value);
if (res != ERROR_OK)
return res;
COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], value);
if (CMD_ARGC == 2) {
uint64_t mask_temp;
res = CALL_COMMAND_HANDLER(get_u64_from_hexarg, 1, &mask_temp);
if (res != ERROR_OK)
return res;
COMMAND_PARSE_NUMBER(u64, CMD_ARGV[1], mask_temp);
mask &= mask_temp;
}
res = samd_modify_user_row_masked(target, value, mask);