lib: json: fix arr_parse()

This function currently fails when decoding an array with number of
elements exactly equal to the maximum available in the struct.

To fix this, move the check for if the current field is past the end
of the array to just before attempting to decode a value. This allows
the last element to be followed by a JSON_TOK_LIST_END token in the
case that the array is full, and the function to return success.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
This commit is contained in:
Marti Bolivar 2017-06-07 14:07:45 -04:00 committed by Anas Nashif
parent 2620ae0932
commit b4c8d83eab

View file

@ -518,16 +518,16 @@ static int arr_parse(struct json_obj *obj,
return 0;
}
if (field == last_elem) {
return -ENOSPC;
}
if (decode_value(obj, elem_descr, &value, field, val) < 0) {
return -EINVAL;
}
(*elements)++;
field = (char *)field + elem_size;
if (field == last_elem) {
return -ENOSPC;
}
}
return -EINVAL;