tools: add some check when parsing the profile info

Fail when we can't parse the profile info to avoid using invalid
values.
This commit is contained in:
Wim Taymans 2021-03-27 20:37:26 +01:00
parent ae22852a9b
commit c85a04fb49
2 changed files with 20 additions and 17 deletions

View file

@ -95,18 +95,17 @@ struct point {
static int process_info(struct data *d, const struct spa_pod *pod, struct driver *info)
{
spa_pod_parse_struct(pod,
return spa_pod_parse_struct(pod,
SPA_POD_Long(&info->count),
SPA_POD_Float(&info->cpu_load[0]),
SPA_POD_Float(&info->cpu_load[1]),
SPA_POD_Float(&info->cpu_load[2]),
SPA_POD_Int(&info->xrun_count));
return 0;
}
static int process_clock(struct data *d, const struct spa_pod *pod, struct driver *info)
{
spa_pod_parse_struct(pod,
return spa_pod_parse_struct(pod,
SPA_POD_Int(&info->clock.flags),
SPA_POD_Int(&info->clock.id),
SPA_POD_Stringn(info->clock.name, sizeof(info->clock.name)),
@ -117,7 +116,6 @@ static int process_clock(struct data *d, const struct spa_pod *pod, struct drive
SPA_POD_Long(&info->clock.delay),
SPA_POD_Double(&info->clock.rate_diff),
SPA_POD_Long(&info->clock.next_nsec));
return 0;
}
static struct node *find_node(struct data *d, uint32_t id)
@ -162,9 +160,10 @@ static int process_driver_block(struct data *d, const struct spa_pod *pod, struc
uint32_t id = 0;
struct measurement m;
struct node *n;
int res;
spa_zero(m);
spa_pod_parse_struct(pod,
if ((res = spa_pod_parse_struct(pod,
SPA_POD_Int(&id),
SPA_POD_String(&name),
SPA_POD_Long(&m.prev_signal),
@ -172,7 +171,8 @@ static int process_driver_block(struct data *d, const struct spa_pod *pod, struc
SPA_POD_Long(&m.awake),
SPA_POD_Long(&m.finish),
SPA_POD_Int(&m.status),
SPA_POD_Fraction(&m.latency));
SPA_POD_Fraction(&m.latency))) < 0)
return res;
if ((n = find_node(d, id)) == NULL)
return -ENOENT;
@ -196,9 +196,10 @@ static int process_follower_block(struct data *d, const struct spa_pod *pod, str
const char *name = NULL;
struct measurement m;
struct node *n;
int res;
spa_zero(m);
spa_pod_parse_struct(pod,
if ((res = spa_pod_parse_struct(pod,
SPA_POD_Int(&id),
SPA_POD_String(&name),
SPA_POD_Long(&m.prev_signal),
@ -206,7 +207,8 @@ static int process_follower_block(struct data *d, const struct spa_pod *pod, str
SPA_POD_Long(&m.awake),
SPA_POD_Long(&m.finish),
SPA_POD_Int(&m.status),
SPA_POD_Fraction(&m.latency));
SPA_POD_Fraction(&m.latency))) < 0)
return res;
if ((n = find_node(d, id)) == NULL)
return -ENOENT;