diff options
author | Christopher Head <chead@zaber.com> | 2019-09-09 13:52:51 -0700 |
---|---|---|
committer | Tomas Vanek <vanekt@fbl.cz> | 2019-09-24 05:47:18 +0100 |
commit | 31a3324b68827ed7fd6c545d04373b63bd828d6b (patch) | |
tree | 4633f37dfee76233916e153057f5d704989540c6 | |
parent | 181d594205f91969b0effdbc97e3d689d28e4cb3 (diff) | |
download | riscv-openocd-31a3324b68827ed7fd6c545d04373b63bd828d6b.zip riscv-openocd-31a3324b68827ed7fd6c545d04373b63bd828d6b.tar.gz riscv-openocd-31a3324b68827ed7fd6c545d04373b63bd828d6b.tar.bz2 |
helper/command: clear errno before calling parser
The C standard says that errno is set to ERANGE if an out-of-range value
is returned by strtol, strtoul, et. al., but it does not say that errno
is cleared if the function is successful (and, indeed, it is not on
glibc). This means that, if errno is ERANGE before strtol is called, and
if the value to be converted is exactly the maximum (or, for a signed
conversion, the minimum) legal value, COMMAND_PARSE_NUMBER will
erroneously indicate that the value is out of range.
Change-Id: I8a8b50a815b408a38235968f1c1d70297ea1a6aa
Signed-off-by: Christopher Head <chead@zaber.com>
Reviewed-on: http://openocd.zylin.com/5298
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
-rw-r--r-- | src/helper/command.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/helper/command.c b/src/helper/command.c index 7b93df6..d969933 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -1394,6 +1394,7 @@ void process_jim_events(struct command_context *cmd_ctx) return ERROR_COMMAND_ARGUMENT_INVALID; \ } \ char *end; \ + errno = 0; \ *ul = func(str, &end, 0); \ if (*end) { \ LOG_ERROR("Invalid command argument"); \ |