Update of /cvsroot/alsa/alsa-lib/src/mixer In directory usw-pr-cvs1:/tmp/cvs-serv1903
Modified Files: simple.c Log Message: replaced excessive asserts with normal conditionals. this _might_ cure some problems on powermac driver... Index: simple.c =================================================================== RCS file: /cvsroot/alsa/alsa-lib/src/mixer/simple.c,v retrieving revision 1.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- simple.c 2 May 2002 10:58:10 -0000 1.54 +++ simple.c 3 Sep 2002 15:53:59 -0000 1.55 @@ -217,13 +217,19 @@ static long to_user(selem_t *s, int dir, selem_ctl_t *c, long value) { - int64_t n = (int64_t) (value - c->min) * (s->str[dir].max - s->str[dir].min); + int64_t n; + if (c->max == c->min) + return s->str[dir].min; + n = (int64_t) (value - c->min) * (s->str[dir].max - s->str[dir].min); return s->str[dir].min + (n + (c->max - c->min) / 2) / (c->max - c->min); } static long from_user(selem_t *s, int dir, selem_ctl_t *c, long value) { - int64_t n = (int64_t) (value - s->str[dir].min) * (c->max - c->min); + int64_t n; + if (s->str[dir].max == s->str[dir].min) + return c->min; + n = (int64_t) (value - s->str[dir].min) * (c->max - c->min); return c->min + (n + (s->str[dir].max - s->str[dir].min) / 2) / (s->str[dir].max - s->str[dir].min); } @@ -803,7 +809,8 @@ const char *name1; memset(&info, 0, sizeof(info)); err = snd_hctl_elem_info(helem, &info); - assert(err >= 0); + if (err < 0) + return err; switch (type) { case CTL_SINGLE: if (info.type != SND_CTL_ELEM_TYPE_BOOLEAN && @@ -866,7 +873,6 @@ } else { simple = melem->private_data; } - assert(!simple->ctls[type].elem); simple->ctls[type].elem = helem; simple->ctls[type].type = info.type; simple->ctls[type].access = info.access; @@ -884,7 +890,8 @@ if (err < 0) return err; err = simple_update(melem); - assert(err >= 0); + if (err < 0) + return err; if (new) err = snd_mixer_elem_add(melem, class); else @@ -920,7 +927,8 @@ const char *n; snd_ctl_elem_info_set_item(info, k); err = snd_hctl_elem_info(helem, info); - assert(err >= 0); + if (err < 0) + return err; n = snd_ctl_elem_info_get_item_name(info); err = simple_add1(class, n, helem, CTL_CAPTURE_SOURCE, k); if (err < 0) @@ -959,7 +967,8 @@ assert(k <= CTL_LAST); simple->ctls[k].elem = NULL; err = snd_mixer_elem_detach(melem, helem); - assert(err >= 0); + if (err < 0) + return err; if (snd_mixer_elem_empty(melem)) return snd_mixer_elem_remove(melem); err = simple_update(melem); @@ -1133,8 +1142,10 @@ static int _snd_mixer_selem_set_volume(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, long value) { selem_t *s = elem->private_data; - assert((unsigned int) channel < s->str[dir].channels); - assert(value >= s->str[dir].min && value <= s->str[dir].max); + if ((unsigned int) channel >= s->str[dir].channels) + return 0; + if (value < s->str[dir].min || value > s->str[dir].max) + return 0; if (s->caps & (dir == PLAY ? CAP_PVOLUME_JOIN : CAP_CVOLUME_JOIN)) channel = 0; @@ -1150,7 +1161,8 @@ int changed = 0; snd_mixer_selem_channel_id_t channel; selem_t *s = elem->private_data; - assert(value >= s->str[dir].min && value <= s->str[dir].max); + if (value < s->str[dir].min || value > s->str[dir].max) + return 0; for (channel = 0; (unsigned int) channel < s->str[dir].channels; channel++) { if (value != s->str[dir].vol[channel]) { s->str[dir].vol[channel] = value; @@ -1163,7 +1175,8 @@ static int _snd_mixer_selem_set_switch(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, int value) { selem_t *s = elem->private_data; - assert((unsigned int) channel < s->str[dir].channels); + if ((unsigned int) channel >= s->str[dir].channels) + return 0; if (s->caps & (dir == PLAY ? CAP_PSWITCH_JOIN : CAP_CSWITCH_JOIN)) channel = 0; @@ -1298,7 +1311,6 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert(min != max); s->str[PLAY].range = 1; s->str[PLAY].min = min; s->str[PLAY].max = max; @@ -1373,8 +1385,10 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert((unsigned int) channel < s->str[PLAY].channels); - assert(s->caps & (CAP_PVOLUME|CAP_GVOLUME)); + if ((unsigned int) channel >= s->str[PLAY].channels) + return -EINVAL; + if (! (s->caps & (CAP_PVOLUME|CAP_GVOLUME))) + return -EINVAL; if (s->caps & CAP_PVOLUME_JOIN) channel = 0; *value = s->str[PLAY].vol[channel]; @@ -1394,8 +1408,10 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert((unsigned int) channel < s->str[PLAY].channels); - assert(s->caps & (CAP_PSWITCH|CAP_GSWITCH)); + if ((unsigned int) channel >= s->str[PLAY].channels) + return -EINVAL; + if (! (s->caps & (CAP_PSWITCH|CAP_GSWITCH))) + return -EINVAL; if (s->caps & CAP_PSWITCH_JOIN) channel = 0; *value = !!(s->str[PLAY].sw & (1 << channel)); @@ -1416,7 +1432,8 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert(s->caps & (CAP_GVOLUME|CAP_PVOLUME)); + if (! (s->caps & (CAP_GVOLUME|CAP_PVOLUME))) + return -EINVAL; changed = _snd_mixer_selem_set_volume(elem, PLAY, channel, value); if (changed < 0) return changed; @@ -1438,7 +1455,8 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert(s->caps & (CAP_GVOLUME|CAP_PVOLUME)); + if (! (s->caps & (CAP_GVOLUME|CAP_PVOLUME))) + return -EINVAL; changed = _snd_mixer_selem_set_volume_all(elem, PLAY, value); if (changed < 0) return changed; @@ -1461,7 +1479,8 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert(s->caps & (CAP_GSWITCH|CAP_PSWITCH)); + if (! (s->caps & (CAP_GSWITCH|CAP_PSWITCH))) + return -EINVAL; changed = _snd_mixer_selem_set_switch(elem, PLAY, channel, value); if (changed < 0) return changed; @@ -1483,7 +1502,8 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert(s->caps & (CAP_GSWITCH|CAP_PSWITCH)); + if (! (s->caps & (CAP_GSWITCH|CAP_PSWITCH))) + return -EINVAL; changed = _snd_mixer_selem_set_switch_all(elem, PLAY, value); if (changed < 0) return changed; @@ -1551,7 +1571,6 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert(min != max); s->str[CAPT].range = 1; s->str[CAPT].min = min; s->str[CAPT].max = max; @@ -1638,7 +1657,8 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert(s->caps & CAP_CSWITCH_EXCL); + if (! (s->caps & CAP_CSWITCH_EXCL)) + return -EINVAL; return s->capture_group; } @@ -1655,8 +1675,10 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert((unsigned int) channel < s->str[CAPT].channels); - assert(s->caps & (CAP_GVOLUME|CAP_CVOLUME)); + if ((unsigned int) channel >= s->str[CAPT].channels) + return -EINVAL; + if (! (s->caps & (CAP_GVOLUME|CAP_CVOLUME))) + return -EINVAL; if (s->caps & CAP_CVOLUME_JOIN) channel = 0; *value = s->str[CAPT].vol[channel]; @@ -1676,8 +1698,10 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert((unsigned int) channel < s->str[CAPT].channels); - assert(s->caps & (CAP_GSWITCH | CAP_CSWITCH)); + if ((unsigned int) channel >= s->str[CAPT].channels) + return -EINVAL; + if (! (s->caps & (CAP_GSWITCH | CAP_CSWITCH))) + return -EINVAL; if (s->caps & CAP_CSWITCH_JOIN) channel = 0; *value = !!(s->str[CAPT].sw & (1 << channel)); @@ -1698,7 +1722,8 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert(s->caps & (CAP_GVOLUME | CAP_CVOLUME)); + if (! (s->caps & (CAP_GVOLUME | CAP_CVOLUME))) + return -EINVAL; changed = _snd_mixer_selem_set_volume(elem, CAPT, channel, value); if (changed < 0) return changed; @@ -1720,7 +1745,8 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert(s->caps & (CAP_GVOLUME | CAP_CVOLUME)); + if (! (s->caps & (CAP_GVOLUME | CAP_CVOLUME))) + return -EINVAL; changed = _snd_mixer_selem_set_volume_all(elem, CAPT, value); if (changed < 0) return changed; @@ -1743,7 +1769,8 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert(s->caps & (CAP_GSWITCH | CAP_CSWITCH)); + if (! (s->caps & (CAP_GSWITCH | CAP_CSWITCH))) + return -EINVAL; changed = _snd_mixer_selem_set_switch(elem, CAPT, channel, value); if (changed < 0) return changed; @@ -1765,7 +1792,8 @@ assert(elem); assert(elem->type == SND_MIXER_ELEM_SIMPLE); s = elem->private_data; - assert(s->caps & (CAP_GSWITCH | CAP_CSWITCH)); + if (! (s->caps & (CAP_GSWITCH | CAP_CSWITCH))) + return -EINVAL; changed = _snd_mixer_selem_set_switch_all(elem, CAPT, value); if (changed < 0) return changed; ------------------------------------------------------- This sf.net email is sponsored by: OSDN - Tired of that same old cell phone? Get a new here for FREE! https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 _______________________________________________ Alsa-cvslog mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/alsa-cvslog