From 5853e1150b8241e6cc77d617ee43bdc84145b273 Mon Sep 17 00:00:00 2001 From: Demi Marie Obenour Date: Fri, 25 Jul 2025 16:54:20 -0400 Subject: [PATCH] *: rely on checks now done by spa_pod_get_values() Rely on spa_pod_get_values() to return no values if the size is too small for the type. This means that if there is a check that at least one value is returned, checking that the size is large enough is unnecessary. --- pipewire-v4l2/src/pipewire-v4l2.c | 4 ++-- spa/include/spa/debug/format.h | 3 +-- spa/include/spa/pod/filter.h | 6 ++---- spa/plugins/videoconvert/videoconvert-ffmpeg.c | 5 +---- src/modules/module-protocol-pulse/format.c | 2 +- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/pipewire-v4l2/src/pipewire-v4l2.c b/pipewire-v4l2/src/pipewire-v4l2.c index 8fc07151a..a832ceef6 100644 --- a/pipewire-v4l2/src/pipewire-v4l2.c +++ b/pipewire-v4l2/src/pipewire-v4l2.c @@ -2255,7 +2255,7 @@ static int vidioc_queryctrl(struct file *file, struct v4l2_queryctrl *arg) // check type and populate range pod = spa_pod_get_values(type, &n_vals, &choice); - if (spa_pod_is_int(pod)) { + if (pod->type == SPA_TYPE_Int) { if (n_vals < 4) break; arg->type = V4L2_CTRL_TYPE_INTEGER; @@ -2330,7 +2330,7 @@ static int vidioc_g_ctrl(struct file *file, struct v4l2_control *arg) if (ctrl_id == arg->id) { // TODO: support getting true ctrl values instead of defaults pod = spa_pod_get_values(type, &n_vals, &choice); - if (spa_pod_is_int(pod)) { + if (pod->type == SPA_TYPE_Int) { if (n_vals < 4) break; int *v = SPA_POD_BODY(pod); diff --git a/spa/include/spa/debug/format.h b/spa/include/spa/debug/format.h index 874dd094a..1448ae223 100644 --- a/spa/include/spa/debug/format.h +++ b/spa/include/spa/debug/format.h @@ -164,8 +164,7 @@ SPA_API_DEBUG_FORMAT int spa_debugc_format(struct spa_debug_context *ctx, int in type = val->type; size = val->size; - if (type < SPA_TYPE_None || type >= _SPA_TYPE_LAST || n_vals < 1 || - size < spa_pod_type_size(type)) + if (type < SPA_TYPE_None || type >= _SPA_TYPE_LAST || n_vals < 1) continue; vals = SPA_POD_BODY(val); diff --git a/spa/include/spa/pod/filter.h b/spa/include/spa/pod/filter.h index 836095029..8eff1da37 100644 --- a/spa/include/spa/pod/filter.h +++ b/spa/include/spa/pod/filter.h @@ -82,7 +82,7 @@ spa_pod_filter_prop(struct spa_pod_builder *b, v1 = spa_pod_get_values(&p1->value, &nalt1, &p1c); v2 = spa_pod_get_values(&p2->value, &nalt2, &p2c); - /* empty choices */ + /* empty or bogus choices */ if (nalt1 < 1 || nalt2 < 1) return -EINVAL; @@ -95,8 +95,6 @@ spa_pod_filter_prop(struct spa_pod_builder *b, /* incompatible property types */ if (type != v2->type || size != v2->size || p1->key != p2->key) return -EINVAL; - if (size < spa_pod_type_size(type)) - return -EINVAL; /* start with copying the property */ spa_pod_builder_prop(b, p1->key, p1->flags & p2->flags); @@ -405,7 +403,7 @@ SPA_API_POD_FILTER int spa_pod_filter_object_make(struct spa_pod_object *pod) struct spa_pod *v = spa_pod_get_values(&res->value, &nvals, &choice); const void *vals = SPA_POD_BODY(v); - if (v->size < spa_pod_type_size(v->type)) + if (nvals < 1) continue; if (spa_pod_compare_is_valid_choice(v->type, v->size, diff --git a/spa/plugins/videoconvert/videoconvert-ffmpeg.c b/spa/plugins/videoconvert/videoconvert-ffmpeg.c index 525b2c933..d0fd4bbbd 100644 --- a/spa/plugins/videoconvert/videoconvert-ffmpeg.c +++ b/spa/plugins/videoconvert/videoconvert-ffmpeg.c @@ -1209,10 +1209,7 @@ static struct spa_pod *transform_format(struct impl *this, struct port *port, co uint32_t n_vals, choice, *id_vals; struct spa_pod *val = spa_pod_get_values(&prop->value, &n_vals, &choice); - if (n_vals < 1) - return 0; - - if (!spa_pod_is_id(val)) + if (n_vals < 1 || val->type != SPA_TYPE_Id) return 0; id_vals = SPA_POD_BODY(val); diff --git a/src/modules/module-protocol-pulse/format.c b/src/modules/module-protocol-pulse/format.c index e3d438c93..34a835ef8 100644 --- a/src/modules/module-protocol-pulse/format.c +++ b/src/modules/module-protocol-pulse/format.c @@ -683,7 +683,7 @@ static int add_int(struct format_info *info, const char *k, struct spa_pod *para return -ENOENT; val = spa_pod_get_values(&prop->value, &n_values, &choice); - if (!spa_pod_is_int(val)) + if (val->type != SPA_TYPE_Int) return -ENOTSUP; if (n_values == 0)