[alsa-lib][PATCH 6/6] ctl: drop deprecated API to compare a pair of control element IDs

Takashi Sakamoto o-takashi at sakamocchi.jp
Thu Mar 18 11:30:13 CET 2021


A commit 2cfe6addaef6 ("control: add snd_ctl_elem_id_compare()
function") adds 'snd_ctl_elem_id_compare()' API, however the
implementation has several bugs.

At first, the name is not inappropriate since it implements one of
comparison algorithms. The name itself implies the algorithm is single
and unique for control element ID.

Secondary, it subtracts a pair of values in fields of 'unsigned int' type
in storage size of the type. It brings integer overflow.

Tertiary, it compares subdevice field in the same structure.

Fortunately, the issued API is not public in any release. An alternative
API, 'snd_ctl_elem_id_compare_by_name_arithmetic()', is already added with
enough tests. This commit drops the issued API.

Signed-off-by: Takashi Sakamoto <o-takashi at sakamocchi.jp>
---
 include/control.h     |  1 -
 src/control/control.c | 35 -----------------------------------
 2 files changed, 36 deletions(-)

diff --git a/include/control.h b/include/control.h
index 1b2cc0c6..3975f4b7 100644
--- a/include/control.h
+++ b/include/control.h
@@ -428,7 +428,6 @@ int snd_ctl_elem_id_equal_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r);
 int snd_ctl_elem_id_equal_by_tuple(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r);
 int snd_ctl_elem_id_compare_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r);
 int snd_ctl_elem_id_compare_by_tuple_arithmetic(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r);
-int snd_ctl_elem_id_compare(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 fbc6aeb7..1d83cb6a 100644
--- a/src/control/control.c
+++ b/src/control/control.c
@@ -1936,41 +1936,6 @@ int snd_ctl_elem_id_compare_by_tuple_arithmetic(snd_ctl_elem_id_t *l, snd_ctl_el
 	return compare_unsigned_integer(l->index, r->index);
 }
 
-/**
- * \brief compare one #snd_ctl_elem_id_t to another
- * \param id1 pointer to first id
- * \param id2 pointer to second id
- * \retval zero when values are identical, other value on a difference (like strcmp)
- *
- * 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,
- * 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 d;
-
-	assert(id1 && id2);
-	d = id1->iface - id2->iface;
-	if (d != 0)
-		return d;
-	d = id1->device - id2->device;
-	if (d != 0)
-		return d;
-	d = id2->subdevice - id2->subdevice;
-	if (d != 0)
-		return d;
-	d = strcmp((const char *)id1->name, (const char *)id2->name);
-	if (d != 0)
-		return d;
-	return id1->index - id2->index;
-}
-
 /**
  * \brief Get numeric identifier from a CTL element identifier
  * \param obj CTL element identifier
-- 
2.27.0



More information about the Alsa-devel mailing list