spa: json: propagate parse error in spa_json_container_len
Successful return is always >= 2 since it includes {} or [], so use 0 to indicate error. Since there's existing code that doesn't check the return value, it's better to use 0 for errors as it'll likely to just lead to producing an empty string if the value is not checked.
This commit is contained in:
parent
31e5823010
commit
f45d89b75b
|
@ -281,12 +281,20 @@ static inline int spa_json_is_container(const char *val, int len)
|
|||
return len > 0 && (*val == '{' || *val == '[');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return length of container at current position, starting at \a value.
|
||||
*
|
||||
* \return Length of container including {} or [], or 0 on error.
|
||||
*/
|
||||
static inline int spa_json_container_len(struct spa_json *iter, const char *value, int len SPA_UNUSED)
|
||||
{
|
||||
const char *val;
|
||||
struct spa_json sub;
|
||||
int res;
|
||||
spa_json_enter(iter, &sub);
|
||||
while (spa_json_next(&sub, &val) > 0);
|
||||
while ((res = spa_json_next(&sub, &val)) > 0);
|
||||
if (res < 0)
|
||||
return 0;
|
||||
return sub.cur + 1 - value;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue