From de22ca68dafa100e49fca43a751e2220e49c4238 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 1 Apr 2020 12:40:48 +0200 Subject: [PATCH] filter: return the newly filtered object Always take the state of the builder to get the newly filtered object, even in the case there is no filter. Handle the case where we can't copy the pod in the case of a NULL filter by reverting the state of the builder. Rework the function a bit to make it possible to pass a NULL result (to calculate the required size, for example) Fixes #226 --- spa/include/spa/pod/filter.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/spa/include/spa/pod/filter.h b/spa/include/spa/pod/filter.h index 92d49229e..b658e61a8 100644 --- a/spa/include/spa/pod/filter.h +++ b/spa/include/spa/pod/filter.h @@ -378,20 +378,18 @@ spa_pod_filter(struct spa_pod_builder *b, spa_return_val_if_fail(pod != NULL, -EINVAL); spa_return_val_if_fail(b != NULL, -EINVAL); - if (filter == NULL) { - spa_pod_builder_raw_padded(b, pod, SPA_POD_SIZE(pod)); - *result = (struct spa_pod*)b->data; - if (!*result) - return -EINVAL; - return 0; - } - spa_pod_builder_get_state(b, &state); - if ((res = spa_pod_filter_part(b, pod, SPA_POD_SIZE(pod), filter, SPA_POD_SIZE(filter))) < 0) { - spa_pod_builder_reset(b, &state); - } + if (filter == NULL) + res = spa_pod_builder_raw_padded(b, pod, SPA_POD_SIZE(pod)); else - *result = (struct spa_pod*)spa_pod_builder_deref(b, state.offset); + res = spa_pod_filter_part(b, pod, SPA_POD_SIZE(pod), filter, SPA_POD_SIZE(filter)); + if (res < 0) { + spa_pod_builder_reset(b, &state); + } else if (result) { + *result = (struct spa_pod*)spa_pod_builder_deref(b, state.offset); + if (*result == NULL) + res = -EINVAL; + } return res; }