From 6f4b96ecc985b1b7a1b9276d981bab538a34a91b Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 23 Mar 2021 17:30:25 +0100 Subject: [PATCH] control: rename snd_ctl_elem_id_compare() to snd_ctl_elem_id_compare_set() - add asserts to check if the unsigned integers are in the valid range - replace tuple with set in the id description - add const prefix for id1 Signed-off-by: Jaroslav Kysela --- include/control.h | 2 +- src/control/control.c | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/control.h b/include/control.h index 40ac2e97..9e52f4c0 100644 --- a/include/control.h +++ b/include/control.h @@ -424,7 +424,7 @@ int snd_ctl_elem_id_malloc(snd_ctl_elem_id_t **ptr); void snd_ctl_elem_id_free(snd_ctl_elem_id_t *obj); void snd_ctl_elem_id_clear(snd_ctl_elem_id_t *obj); void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src); -int snd_ctl_elem_id_compare(snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2); +int snd_ctl_elem_id_compare_set(const snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2); unsigned int snd_ctl_elem_id_get_numid(const snd_ctl_elem_id_t *obj); snd_ctl_elem_iface_t snd_ctl_elem_id_get_interface(const snd_ctl_elem_id_t *obj); unsigned int snd_ctl_elem_id_get_device(const snd_ctl_elem_id_t *obj); diff --git a/src/control/control.c b/src/control/control.c index 2e112579..3f98817c 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -77,12 +77,12 @@ Each element has the following identifying properties: - Its name - Its index -An element can be identified either by its numid or by the tuple -(interface type, device, subdevice, name, index). This tuple is always -the same (driver updates can change it, but in practice this is -rare). The numid can change on each boot. In case of an USB sound -card, the numid can also change when it is reconnected. - +An element can be identified either by its short numid or by the full +set of fields (interface type, device, subdevice, name, index). +This set of fields is always the same (driver updates can change it, +but in practice this is rare). The numid can change on each boot. +In case of an USB sound card, the numid can also change when it +is reconnected. The short numid is used to reduce the lookup time. \section element_lists Element Lists @@ -153,6 +153,7 @@ against the original design. #include #include #include +#include #include "control_local.h" /** @@ -1827,17 +1828,21 @@ void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src) * This comparison ignores the numid part. The numid comparison can be easily * implemented using snd_ctl_elem_id_get_numid() calls. * - * The identifier fields are compared in this order: interface, device, + * The identifier set fields are compared in this order: interface, device, * subdevice, name, index. * * The return value can be used for sorting like qsort(). It gives persistent * results. */ -int snd_ctl_elem_id_compare(snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2) +int snd_ctl_elem_id_compare_set(const snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2) { int d; assert(id1 && id2); + /* although those values are unsigned integer, practically, */ + /* the useable limit is really much lower */ + assert((id1->iface | id1->device | id1->subdevice | id1->index) <= INT_MAX); + assert((id2->iface | id2->device | id2->subdevice | id1->index) <= INT_MAX); d = id1->iface - id2->iface; if (d != 0) return d; -- 2.47.1