summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2016-07-20 18:58:52 +0900
committerTakashi Iwai <tiwai@suse.de>2016-07-20 14:32:14 +0200
commitdf43c2d38047a6dd625e20b97ca6efb4fb0120a3 (patch)
tree7cfd3789c2be642461ed7e2f7371de3ff63ae3e6
parent9797e9893093dbbde9745faad5163c93be3ca3a6 (diff)
downloadalsa-lib-df43c2d38047a6dd625e20b97ca6efb4fb0120a3.tar.gz
ctl: use condition statements instead of assert() for new APIs to add an element set
Usage of assert() is not better practice of programming as shared library APIs. They should return appropriate error code to promote applications to handle error state. This commit applies condition statements with return value of -EINVAL, instead of assert(). As a backward compatibility for existent applications, old APIs still call assert(). Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--src/control/control.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/control/control.c b/src/control/control.c
index aa051305..6c00b8e5 100644
--- a/src/control/control.c
+++ b/src/control/control.c
@@ -382,7 +382,8 @@ int snd_ctl_add_integer_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
unsigned int numid;
int err;
- assert(ctl && info && info->id.name[0]);
+ if (ctl == NULL || info == NULL || info->id.name[0] == '\0')
+ return -EINVAL;
info->type = SND_CTL_ELEM_TYPE_INTEGER;
info->access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
@@ -471,7 +472,8 @@ int snd_ctl_add_integer64_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
unsigned int numid;
int err;
- assert(ctl && info && info->id.name[0]);
+ if (ctl == NULL || info == NULL || info->id.name[0] == '\0')
+ return -EINVAL;
info->type = SND_CTL_ELEM_TYPE_INTEGER64;
info->access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
@@ -549,7 +551,8 @@ int snd_ctl_add_boolean_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
unsigned int element_count,
unsigned int member_count)
{
- assert(ctl && info && info->id.name[0]);
+ if (ctl == NULL || info == NULL || info->id.name[0] == '\0')
+ return -EINVAL;
info->type = SND_CTL_ELEM_TYPE_BOOLEAN;
info->access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
@@ -619,7 +622,9 @@ int snd_ctl_add_enumerated_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
char *buf, *p;
int err;
- assert(ctl && info && info->id.name[0] && labels);
+ if (ctl == NULL || info == NULL || info->id.name[0] == '\0' ||
+ labels == NULL)
+ return -EINVAL;
info->type = SND_CTL_ELEM_TYPE_ENUMERATED;
info->access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
@@ -698,7 +703,8 @@ int snd_ctl_add_bytes_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
unsigned int element_count,
unsigned int member_count)
{
- assert(ctl && info && info->id.name[0]);
+ if (ctl == NULL || info == NULL || info->id.name[0] == '\0')
+ return -EINVAL;
info->type = SND_CTL_ELEM_TYPE_BYTES;
info->access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
@@ -726,6 +732,8 @@ int snd_ctl_elem_add_integer(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
{
snd_ctl_elem_info_t info = {0};
+ assert(ctl && id && id->name[0]);
+
info.id = *id;
return snd_ctl_add_integer_elem_set(ctl, &info, 1, member_count,
@@ -745,6 +753,8 @@ int snd_ctl_elem_add_integer64(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
{
snd_ctl_elem_info_t info = {0};
+ assert(ctl && id && id->name[0]);
+
info.id = *id;
return snd_ctl_add_integer64_elem_set(ctl, &info, 1, member_count,
@@ -763,6 +773,8 @@ int snd_ctl_elem_add_boolean(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
{
snd_ctl_elem_info_t info = {0};
+ assert(ctl && id && id->name[0]);
+
info.id = *id;
return snd_ctl_add_boolean_elem_set(ctl, &info, 1, member_count);
@@ -783,6 +795,8 @@ int snd_ctl_elem_add_enumerated(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
{
snd_ctl_elem_info_t info = {0};
+ assert(ctl && id && id->name[0] && labels);
+
info.id = *id;
return snd_ctl_add_enumerated_elem_set(ctl, &info, 1, member_count,