From cbc1dc50490ba7a98778bef352aead754befabca Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Thu, 29 Jul 2021 23:46:31 +0100 Subject: flash/atsame5: 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: Ia7fe9c4017108616f21676f115f151ac62924205 Signed-off-by: Tarek BOCHKATI Reviewed-on: https://review.openocd.org/c/openocd/+/6423 Reviewed-by: Antonio Borneo Tested-by: jenkins --- src/flash/nor/atsame5.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/flash/nor/atsame5.c b/src/flash/nor/atsame5.c index 7c7e5d0..203c470 100644 --- a/src/flash/nor/atsame5.c +++ b/src/flash/nor/atsame5.c @@ -797,11 +797,12 @@ COMMAND_HANDLER(same5_handle_userpage_command) } if (CMD_ARGC >= 1) { - uint64_t mask = NVMUSERROW_SAM_E5_D5_MASK; - uint64_t value = strtoull(CMD_ARGV[0], NULL, 0); + uint64_t value, mask = NVMUSERROW_SAM_E5_D5_MASK; + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], value); if (CMD_ARGC == 2) { - uint64_t mask_temp = strtoull(CMD_ARGV[1], NULL, 0); + uint64_t mask_temp; + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[1], mask_temp); mask &= mask_temp; } @@ -837,7 +838,9 @@ COMMAND_HANDLER(same5_handle_bootloader_command) return ERROR_FAIL; if (CMD_ARGC >= 1) { - unsigned long size = strtoul(CMD_ARGV[0], NULL, 0); + unsigned long size; + + COMMAND_PARSE_NUMBER(ulong, CMD_ARGV[0], size); uint32_t code = (size + 8191) / 8192; if (code > 15) { command_print(CMD, "Invalid bootloader size. Please " -- cgit v1.1