lib: json: Fix number parsing

Comparing *endptr with '\0' will always be true before replacing
*token->end with prev_end.

Jira: ZEP-1607
Change-Id: I224129586e15380d3919bfba3db4fcf38c28cb07
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
This commit is contained in:
Leandro Pereira 2017-03-21 15:49:25 -07:00 committed by Anas Nashif
commit 844ef6744e

View file

@ -389,8 +389,7 @@ static int arr_next(struct json_obj *json, struct token *value)
static int decode_num(const struct token *token, int32_t *num) static int decode_num(const struct token *token, int32_t *num)
{ {
/* FIXME: strtod() is not available in newlib/minimal libc, /* FIXME: strtod() is not available in newlib/minimal libc,
* so using strtol() here; this means no floating point * so using strtol() here.
* numbers.
*/ */
char *endptr; char *endptr;
char prev_end; char prev_end;
@ -407,7 +406,7 @@ static int decode_num(const struct token *token, int32_t *num)
return -errno; return -errno;
} }
if (*endptr) { if (endptr != token->end) {
return -EINVAL; return -EINVAL;
} }