From 18ff08243bc2819d0f4e09f9a8fec6a6ef7a9767 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 13 Nov 2025 18:13:02 +0100 Subject: [PATCH] spa: add spa_pod_memcmp Add a helper to memcmp two pods and use it in some places. --- spa/include/spa/param/tag-utils.h | 4 ++-- spa/include/spa/pod/compare.h | 13 ++++++++----- spa/include/spa/pod/filter.h | 4 +--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/spa/include/spa/param/tag-utils.h b/spa/include/spa/param/tag-utils.h index 7d7fbb092..335cb9559 100644 --- a/spa/include/spa/param/tag-utils.h +++ b/spa/include/spa/param/tag-utils.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #ifdef __cplusplus @@ -33,8 +34,7 @@ extern "C" { SPA_API_TAG_UTILS int spa_tag_compare(const struct spa_pod *a, const struct spa_pod *b) { - return ((a == b) || (a && b && SPA_POD_SIZE(a) == SPA_POD_SIZE(b) && - memcmp(a, b, SPA_POD_SIZE(b)) == 0)) ? 0 : 1; + return spa_pod_memcmp(a, b); } SPA_API_TAG_UTILS int diff --git a/spa/include/spa/pod/compare.h b/spa/include/spa/pod/compare.h index 144bd4a5a..8dca7e9ed 100644 --- a/spa/include/spa/pod/compare.h +++ b/spa/include/spa/pod/compare.h @@ -80,6 +80,13 @@ SPA_API_POD_COMPARE int spa_pod_compare_value(uint32_t type, const void *r1, con return 0; } +SPA_API_POD_COMPARE int spa_pod_memcmp(const struct spa_pod *a, + const struct spa_pod *b) +{ + return ((a == b) || (a && b && SPA_POD_SIZE(a) == SPA_POD_SIZE(b) && + memcmp(a, b, SPA_POD_SIZE(b)) == 0)) ? 0 : 1; +} + SPA_API_POD_COMPARE int spa_pod_compare(const struct spa_pod *pod1, const struct spa_pod *pod2) { @@ -149,12 +156,8 @@ SPA_API_POD_COMPARE int spa_pod_compare(const struct spa_pod *pod1, break; } case SPA_TYPE_Array: - { - if (pod1->size != pod2->size) - return -EINVAL; - res = memcmp(SPA_POD_BODY(pod1), SPA_POD_BODY(pod2), pod2->size); + res = spa_pod_memcmp(pod1, pod2); break; - } default: if (pod1->size != pod2->size) return -EINVAL; diff --git a/spa/include/spa/pod/filter.h b/spa/include/spa/pod/filter.h index 93d9a51ea..50ae28391 100644 --- a/spa/include/spa/pod/filter.h +++ b/spa/include/spa/pod/filter.h @@ -339,9 +339,7 @@ SPA_API_POD_FILTER int spa_pod_filter_part(struct spa_pod_builder *b, default: if (pf != NULL) { - if (pp->size != pf->size) - return -EINVAL; - if (memcmp(pp, pf, pp->size) != 0) + if (spa_pod_memcmp(pp, pf) != 0) return -EINVAL; do_advance = true; }