]> git.alsa-project.org Git - alsa-lib.git/commitdiff
ctl: use condition statements instead of assert() for new APIs to add an element set
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 20 Jul 2016 09:58:52 +0000 (18:58 +0900)
committerTakashi Iwai <tiwai@suse.de>
Wed, 20 Jul 2016 12:32:14 +0000 (14:32 +0200)
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>
src/control/control.c

index aa051305a449d17d399817aa077a0cd86483c977..6c00b8e50d2be78f9c5e93322b8e8b107ff8c442 100644 (file)
@@ -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,