mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
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
1 changed files with 9 additions and 1 deletions
|
|
@ -281,12 +281,20 @@ static inline int spa_json_is_container(const char *val, int len)
|
||||||
return len > 0 && (*val == '{' || *val == '[');
|
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)
|
static inline int spa_json_container_len(struct spa_json *iter, const char *value, int len SPA_UNUSED)
|
||||||
{
|
{
|
||||||
const char *val;
|
const char *val;
|
||||||
struct spa_json sub;
|
struct spa_json sub;
|
||||||
|
int res;
|
||||||
spa_json_enter(iter, &sub);
|
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;
|
return sub.cur + 1 - value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue