diff options
author | Pierce Lopez <pierce.lopez@gmail.com> | 2020-05-10 13:20:02 -0400 |
---|---|---|
committer | Pierce Lopez <pierce.lopez@gmail.com> | 2020-05-10 13:38:12 -0400 |
commit | 003b58782b12798da3da8b952152988a88dfb532 (patch) | |
tree | cbff6cafc25a3407adc58b00a5b62d4469ba349b /json_util.c | |
parent | 26f080997d41cfdb17beab65e90c82217d0ac43b (diff) | |
download | json-c-003b58782b12798da3da8b952152988a88dfb532.tar.gz |
fix json_parse_uint64() usage of errno
introduced in #542
fixes #601
Diffstat (limited to 'json_util.c')
-rw-r--r-- | json_util.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/json_util.c b/json_util.c index d3ee47d..e8e2ec6 100644 --- a/json_util.c +++ b/json_util.c @@ -245,19 +245,17 @@ int json_parse_uint64(const char *buf, uint64_t *retval) { char *end = NULL; uint64_t val; - errno = 1; + errno = 0; while (*buf == ' ') - { buf++; - } if (*buf == '-') - errno = 0; + return 1; /* error: uint cannot be negative */ val = strtoull(buf, &end, 10); if (end != buf) *retval = val; - return ((errno == 0) || (end == buf)) ? 1 : 0; + return ((val == 0 && errno != 0) || (end == buf)) ? 1 : 0; } #ifndef HAVE_REALLOC |