]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Fixes...
authorJaroslav Kysela <perex@perex.cz>
Sun, 27 Dec 1998 01:01:47 +0000 (01:01 +0000)
committerJaroslav Kysela <perex@perex.cz>
Sun, 27 Dec 1998 01:01:47 +0000 (01:01 +0000)
src/control/cards.c
src/control/control.c
src/mixer/mixer.c
src/pcm/pcm.c
src/rawmidi/rawmidi.c

index eaa8fa7e24c5342075700663e0edad4c3bb2ea12..2af073da55ddc1bcec2ccce964e88197d87214e6 100644 (file)
@@ -75,11 +75,11 @@ int snd_card_name(const char *string)
        void *handle;
        struct snd_ctl_hw_info info;
 
+       if (!string)
+               return -EINVAL;
        bitmask = snd_cards_mask();
        if (!bitmask)
                return -ENODEV;
-       if (!string)
-               return -EINVAL;
        if ((isdigit(*string) && *(string + 1) == 0) ||
            (isdigit(*string) && isdigit(*(string + 1)) && *(string + 2) == 0)) {
                sscanf(string, "%i", &card);
index 3e07936cf64ce5af0e1aab4abf03f499837dac70..520c1a12b23bf8702c6293456f5052fda05fc778 100644 (file)
@@ -95,7 +95,7 @@ int snd_ctl_hw_info(void *handle, struct snd_ctl_hw_info *info)
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !info)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_HW_INFO, info) < 0)
                return -errno;
@@ -122,7 +122,7 @@ int snd_ctl_switch(void *handle, const char *switch_id)
        int idx, switches, err;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !switch_id)
                return -EINVAL;
        /* bellow implementation isn't optimized for speed */
        /* info about switches should be cached in the snd_ctl_t structure */
@@ -137,25 +137,26 @@ int snd_ctl_switch(void *handle, const char *switch_id)
        return -EINVAL;
 }
 
-int snd_ctl_switch_read(void *handle, int switchn, struct snd_ctl_switch *data)
+int snd_ctl_switch_read(void *handle, int switchn, snd_ctl_switch_t *data)
 {
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !data || switchn < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_ctl_switch_t));
        data->switchn = switchn;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_SWITCH_READ, data) < 0)
                return -errno;
        return 0;
 }
 
-int snd_ctl_switch_write(void *handle, int switchn, struct snd_ctl_switch *data)
+int snd_ctl_switch_write(void *handle, int switchn, snd_ctl_switch_t *data)
 {
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !data || switchn < 0)
                return -EINVAL;
        data->switchn = switchn;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_SWITCH_WRITE, data) < 0)
@@ -168,7 +169,7 @@ int snd_ctl_pcm_info(void *handle, int dev, snd_pcm_info_t * info)
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !info || dev < 0)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
                return -errno;
@@ -182,7 +183,7 @@ int snd_ctl_pcm_playback_info(void *handle, int dev, snd_pcm_playback_info_t * i
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !info || dev < 0)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
                return -errno;
@@ -196,7 +197,7 @@ int snd_ctl_pcm_record_info(void *handle, int dev, snd_pcm_record_info_t * info)
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !info || dev < 0)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
                return -errno;
@@ -211,7 +212,7 @@ int snd_ctl_pcm_playback_switches(void *handle, int dev)
        int result;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || dev < 0)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
                return -errno;
@@ -227,7 +228,7 @@ int snd_ctl_pcm_playback_switch(void *handle, int dev, const char *switch_id)
        int idx, switches, err;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !switch_id || dev < 0)
                return -EINVAL;
        /* bellow implementation isn't optimized for speed */
        /* info about switches should be cached in the snd_ctl_t structure */
@@ -247,8 +248,9 @@ int snd_ctl_pcm_playback_switch_read(void *handle, int dev, int switchn, snd_pcm
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !data || dev < 0 || switchn < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_pcm_switch_t));
        data->switchn = switchn;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
                return -errno;
@@ -262,7 +264,7 @@ int snd_ctl_pcm_playback_switch_write(void *handle, int dev, int switchn, snd_pc
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !data || dev < 0 || switchn < 0)
                return -EINVAL;
        data->switchn = switchn;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
@@ -278,7 +280,7 @@ int snd_ctl_pcm_record_switches(void *handle, int dev)
        int result;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || dev < 0)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
                return -errno;
@@ -294,7 +296,7 @@ int snd_ctl_pcm_record_switch(void *handle, int dev, const char *switch_id)
        int idx, switches, err;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !switch_id || dev < 0)
                return -EINVAL;
        /* bellow implementation isn't optimized for speed */
        /* info about switches should be cached in the snd_ctl_t structure */
@@ -314,8 +316,9 @@ int snd_ctl_pcm_record_switch_read(void *handle, int dev, int switchn, snd_pcm_s
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !data || dev < 0 || switchn < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_pcm_switch_t));
        data->switchn = switchn;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
                return -errno;
@@ -329,7 +332,7 @@ int snd_ctl_pcm_record_switch_write(void *handle, int dev, int switchn, snd_pcm_
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !data || dev < 0 || switchn < 0)
                return -EINVAL;
        data->switchn = switchn;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_DEVICE, &dev) < 0)
@@ -344,7 +347,7 @@ int snd_ctl_mixer_info(void *handle, int dev, snd_mixer_info_t * info)
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !info || dev < 0)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_MIXER_DEVICE, &dev) < 0)
                return -errno;
@@ -359,7 +362,7 @@ int snd_ctl_mixer_switches(void *handle, int dev)
        int result;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || dev < 0)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_MIXER_DEVICE, &dev) < 0)
                return -errno;
@@ -375,7 +378,7 @@ int snd_ctl_mixer_switch(void *handle, int dev, const char *switch_id)
        int idx, switches, err;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !switch_id || dev < 0)
                return -EINVAL;
        /* bellow implementation isn't optimized for speed */
        /* info about switches should be cached in the snd_ctl_t structure */
@@ -395,8 +398,9 @@ int snd_ctl_mixer_switch_read(void *handle, int dev, int switchn, snd_mixer_swit
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !data || dev < 0 || switchn < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_mixer_switch_t));
        data->switchn = switchn;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_MIXER_DEVICE, &dev) < 0)
                return -errno;
@@ -410,7 +414,7 @@ int snd_ctl_mixer_switch_write(void *handle, int dev, int switchn, snd_mixer_swi
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !data || dev < 0 || switchn < 0)
                return -EINVAL;
        data->switchn = switchn;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_MIXER_DEVICE, &dev) < 0)
@@ -425,7 +429,7 @@ int snd_ctl_rawmidi_info(void *handle, int dev, snd_rawmidi_info_t * info)
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !info)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
                return -errno;
@@ -439,7 +443,7 @@ int snd_ctl_rawmidi_output_info(void *handle, int dev, snd_rawmidi_output_info_t
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !info || dev < 0)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
                return -errno;
@@ -453,7 +457,7 @@ int snd_ctl_rawmidi_input_info(void *handle, int dev, snd_rawmidi_input_info_t *
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !info || dev < 0)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
                return -errno;
@@ -468,7 +472,7 @@ int snd_ctl_rawmidi_output_switches(void *handle, int dev)
        int result;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || dev < 0)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
                return -errno;
@@ -484,7 +488,7 @@ int snd_ctl_rawmidi_output_switch(void *handle, int dev, const char *switch_id)
        int idx, switches, err;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !switch_id || dev < 0)
                return -EINVAL;
        /* bellow implementation isn't optimized for speed */
        /* info about switches should be cached in the snd_ctl_t structure */
@@ -504,8 +508,9 @@ int snd_ctl_rawmidi_output_switch_read(void *handle, int dev, int switchn, snd_r
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !data || dev < 0 || switchn < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_rawmidi_switch_t));
        data->switchn = switchn;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
                return -errno;
@@ -519,7 +524,7 @@ int snd_ctl_rawmidi_output_switch_write(void *handle, int dev, int switchn, snd_
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !data || dev < 0 || switchn < 0)
                return -EINVAL;
        data->switchn = switchn;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
@@ -535,7 +540,7 @@ int snd_ctl_rawmidi_input_switches(void *handle, int dev)
        int result;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || dev < 0)
                return -EINVAL;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
                return -errno;
@@ -551,7 +556,7 @@ int snd_ctl_rawmidi_input_switch(void *handle, int dev, const char *switch_id)
        int idx, switches, err;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !switch_id || dev < 0)
                return -EINVAL;
        /* bellow implementation isn't optimized for speed */
        /* info about switches should be cached in the snd_ctl_t structure */
@@ -571,8 +576,9 @@ int snd_ctl_rawmidi_input_switch_read(void *handle, int dev, int switchn, snd_ra
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !data || dev < 0 || switchn < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_rawmidi_switch_t));
        data->switchn = switchn;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
                return -errno;
@@ -586,7 +592,7 @@ int snd_ctl_rawmidi_input_switch_write(void *handle, int dev, int switchn, snd_r
        snd_ctl_t *ctl;
 
        ctl = (snd_ctl_t *) handle;
-       if (!ctl)
+       if (!ctl || !data || dev < 0 || switchn < 0)
                return -EINVAL;
        data->switchn = switchn;
        if (ioctl(ctl->fd, SND_CTL_IOCTL_RAWMIDI_DEVICE, &dev) < 0)
index b48171bf003889bdc29e4ccf0b183b90f4522e13..8d38b4ed98e7739c0c3e05d8a6a9724f2f9a9ceb 100644 (file)
@@ -110,7 +110,7 @@ int snd_mixer_info(void *handle, snd_mixer_info_t * info)
        snd_mixer_t *mixer;
 
        mixer = (snd_mixer_t *) handle;
-       if (!mixer)
+       if (!mixer || !info)
                return -EINVAL;
        if (ioctl(mixer->fd, SND_MIXER_IOCTL_INFO, info) < 0)
                return -errno;
@@ -136,7 +136,7 @@ int snd_mixer_channel(void *handle, const char *channel_id)
        int idx, channels, err;
 
        mixer = (snd_mixer_t *) handle;
-       if (!mixer)
+       if (!mixer || !channel_id)
                return -EINVAL;
        /* bellow implementation isn't optimized for speed */
        /* info about channels should be cached in the snd_mixer_t structure */
@@ -156,7 +156,7 @@ int snd_mixer_channel_info(void *handle, int channel, snd_mixer_channel_info_t *
        snd_mixer_t *mixer;
 
        mixer = (snd_mixer_t *) handle;
-       if (!mixer)
+       if (!mixer || !info || channel < 0)
                return -EINVAL;
        info->channel = channel;
        if (ioctl(mixer->fd, SND_MIXER_IOCTL_CHANNEL_INFO, info) < 0)
@@ -169,8 +169,9 @@ int snd_mixer_channel_read(void *handle, int channel, snd_mixer_channel_t * data
        snd_mixer_t *mixer;
 
        mixer = (snd_mixer_t *) handle;
-       if (!mixer)
+       if (!mixer || !data || channel < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_mixer_channel_t));
        data->channel = channel;
        if (ioctl(mixer->fd, SND_MIXER_IOCTL_CHANNEL_READ, data) < 0)
                return -errno;
@@ -182,7 +183,7 @@ int snd_mixer_channel_write(void *handle, int channel, snd_mixer_channel_t * dat
        snd_mixer_t *mixer;
 
        mixer = (snd_mixer_t *) handle;
-       if (!mixer)
+       if (!mixer || !data)
                return -EINVAL;
        data->channel = channel;
        if (ioctl(mixer->fd, SND_MIXER_IOCTL_CHANNEL_WRITE, data) < 0)
@@ -195,8 +196,9 @@ int snd_mixer_channel_record_read(void *handle, int channel, snd_mixer_channel_t
        snd_mixer_t *mixer;
 
        mixer = (snd_mixer_t *) handle;
-       if (!mixer)
+       if (!mixer || !data || channel < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_mixer_channel_t));
        data->channel = channel;
        if (ioctl(mixer->fd, SND_MIXER_IOCTL_CHANNEL_RREAD, data) < 0)
                return -errno;
@@ -208,7 +210,7 @@ int snd_mixer_channel_record_write(void *handle, int channel, snd_mixer_channel_
        snd_mixer_t *mixer;
 
        mixer = (snd_mixer_t *) handle;
-       if (!mixer)
+       if (!mixer || !data || channel < 0)
                return -EINVAL;
        data->channel = channel;
        if (ioctl(mixer->fd, SND_MIXER_IOCTL_CHANNEL_RWRITE, data) < 0)
@@ -236,7 +238,7 @@ int snd_mixer_switch(void *handle, const char *switch_id)
        int idx, switches, err;
 
        mixer = (snd_mixer_t *) handle;
-       if (!mixer)
+       if (!mixer || !switch_id)
                return -EINVAL;
        /* bellow implementation isn't optimized for speed */
        /* info about switches should be cached in the snd_mixer_t structure */
@@ -256,8 +258,9 @@ int snd_mixer_switch_read(void *handle, int switchn, snd_mixer_switch_t * data)
        snd_mixer_t *mixer;
 
        mixer = (snd_mixer_t *) handle;
-       if (!mixer)
+       if (!mixer || !data || switchn < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_mixer_switch_t));
        data->switchn = switchn;
        if (ioctl(mixer->fd, SND_MIXER_IOCTL_SWITCH_READ, data) < 0)
                return -errno;
@@ -269,7 +272,7 @@ int snd_mixer_switch_write(void *handle, int switchn, snd_mixer_switch_t * data)
        snd_mixer_t *mixer;
 
        mixer = (snd_mixer_t *) handle;
-       if (!mixer)
+       if (!mixer || !data || switchn < 0)
                return -EINVAL;
        data->switchn = switchn;
        if (ioctl(mixer->fd, SND_MIXER_IOCTL_SWITCH_WRITE, data) < 0)
index 3a37d49a1f468687c0e60f94396902e430121dba..dec1bef20fffcdd1046464a3bdb18fb3228689df 100644 (file)
@@ -116,7 +116,7 @@ int snd_pcm_info(void *handle, snd_pcm_info_t * info)
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !info)
                return -EINVAL;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_INFO, info) < 0)
                return -errno;
@@ -128,7 +128,7 @@ int snd_pcm_playback_info(void *handle, snd_pcm_playback_info_t * info)
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !info)
                return -EINVAL;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_INFO, info) < 0)
                return -errno;
@@ -140,7 +140,7 @@ int snd_pcm_record_info(void *handle, snd_pcm_record_info_t * info)
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !info)
                return -EINVAL;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_INFO, info) < 0)
                return -errno;
@@ -167,7 +167,7 @@ int snd_pcm_playback_switch(void *handle, const char *switch_id)
        int idx, switches, err;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !switch_id)
                return -EINVAL;
        /* bellow implementation isn't optimized for speed */
        /* info about switches should be cached in the snd_mixer_t structure */
@@ -187,8 +187,9 @@ int snd_pcm_playback_switch_read(void *handle, int switchn, snd_pcm_switch_t * d
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !data || switchn < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_pcm_switch_t));
        data->switchn = switchn;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_PSWITCH_READ, data) < 0)
                return -errno;
@@ -200,7 +201,7 @@ int snd_pcm_playback_switch_write(void *handle, int switchn, snd_pcm_switch_t *
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !data || switchn < 0)
                return -EINVAL;
        data->switchn = switchn;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_PSWITCH_WRITE, data) < 0)
@@ -228,7 +229,7 @@ int snd_pcm_record_switch(void *handle, const char *switch_id)
        int idx, switches, err;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !switch_id)
                return -EINVAL;
        /* bellow implementation isn't optimized for speed */
        /* info about switches should be cached in the snd_mixer_t structure */
@@ -248,8 +249,9 @@ int snd_pcm_record_switch_read(void *handle, int switchn, snd_pcm_switch_t * dat
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !data || switchn < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_pcm_switch_t));
        data->switchn = switchn;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_RSWITCH_READ, data) < 0)
                return -errno;
@@ -261,7 +263,7 @@ int snd_pcm_record_switch_write(void *handle, int switchn, snd_pcm_switch_t * da
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !data || switchn < 0)
                return -EINVAL;
        data->switchn = switchn;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_RSWITCH_WRITE, data) < 0)
@@ -274,7 +276,7 @@ int snd_pcm_playback_format(void *handle, snd_pcm_format_t * format)
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !format)
                return -EINVAL;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_FORMAT, format) < 0)
                return -errno;
@@ -286,7 +288,7 @@ int snd_pcm_record_format(void *handle, snd_pcm_format_t * format)
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !format)
                return -EINVAL;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_FORMAT, format) < 0)
                return -errno;
@@ -298,7 +300,7 @@ int snd_pcm_playback_params(void *handle, snd_pcm_playback_params_t * params)
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !params)
                return -EINVAL;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_PARAMS, params) < 0)
                return -errno;
@@ -310,7 +312,7 @@ int snd_pcm_record_params(void *handle, snd_pcm_record_params_t * params)
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !params)
                return -EINVAL;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_PARAMS, params) < 0)
                return -errno;
@@ -322,7 +324,7 @@ int snd_pcm_playback_status(void *handle, snd_pcm_playback_status_t * status)
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !status)
                return -EINVAL;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_STATUS, status) < 0)
                return -errno;
@@ -334,7 +336,7 @@ int snd_pcm_record_status(void *handle, snd_pcm_record_status_t * status)
        snd_pcm_t *pcm;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || !status)
                return -EINVAL;
        if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_STATUS, status) < 0)
                return -errno;
@@ -419,7 +421,7 @@ ssize_t snd_pcm_write(void *handle, const void *buffer, size_t size)
        ssize_t result;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || (!buffer && size > 0) || size < 0)
                return -EINVAL;
        result = write(pcm->fd, buffer, size);
        if (result < 0)
@@ -433,7 +435,7 @@ ssize_t snd_pcm_read(void *handle, void *buffer, size_t size)
        ssize_t result;
 
        pcm = (snd_pcm_t *) handle;
-       if (!pcm)
+       if (!pcm || (!buffer && size > 0) || size < 0)
                return -EINVAL;
        result = read(pcm->fd, buffer, size);
        if (result < 0)
index 2e5522bee6806fa79c4d71ce295ffdf7604561a8..cfeedf2cf3c0e3087cf2bcd80e31ed097ed35b08 100644 (file)
@@ -29,7 +29,7 @@
 #include "asoundlib.h"
 
 #define SND_FILE_RAWMIDI       "/dev/snd/midi%i%i"
-#define SND_PCM_VERSION_MAX    SND_PROTOCOL_VERSION( 1, 0, 0 )
+#define SND_RAWMIDI_VERSION_MAX        SND_PROTOCOL_VERSION( 1, 0, 0 )
 
 typedef struct {
        int card;
@@ -53,7 +53,7 @@ int snd_rawmidi_open(void **handle, int card, int device, int mode)
                close(fd);
                return -errno;
        }
-       if (SND_PROTOCOL_UNCOMPATIBLE(ver, SND_PCM_VERSION_MAX)) {
+       if (SND_PROTOCOL_UNCOMPATIBLE(ver, SND_RAWMIDI_VERSION_MAX)) {
                close(fd);
                return -SND_ERROR_UNCOMPATIBLE_VERSION;
        }
@@ -116,7 +116,7 @@ int snd_rawmidi_info(void *handle, snd_rawmidi_info_t * info)
        snd_rawmidi_t *rmidi;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || !info)
                return -EINVAL;
        if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_INFO, info) < 0)
                return -errno;
@@ -143,7 +143,7 @@ int snd_rawmidi_output_switch(void *handle, const char *switch_id)
        int idx, switches, err;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || !switch_id)
                return -EINVAL;
        /* bellow implementation isn't optimized for speed */
        /* info about switches should be cached in the snd_mixer_t structure */
@@ -163,8 +163,9 @@ int snd_rawmidi_output_switch_read(void *handle, int switchn, snd_rawmidi_switch
        snd_rawmidi_t *rmidi;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || !data || switchn < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_rawmidi_switch_t));
        data->switchn = switchn;
        if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_OSWITCH_READ, data) < 0)
                return -errno;
@@ -176,7 +177,7 @@ int snd_rawmidi_output_switch_write(void *handle, int switchn, snd_rawmidi_switc
        snd_rawmidi_t *rmidi;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || !data || switchn < 0)
                return -EINVAL;
        data->switchn = switchn;
        if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_OSWITCH_WRITE, data) < 0)
@@ -204,7 +205,7 @@ int snd_rawmidi_input_switch(void *handle, const char *switch_id)
        int idx, switches, err;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || !switch_id)
                return -EINVAL;
        /* bellow implementation isn't optimized for speed */
        /* info about switches should be cached in the snd_mixer_t structure */
@@ -224,8 +225,9 @@ int snd_rawmidi_input_switch_read(void *handle, int switchn, snd_rawmidi_switch_
        snd_rawmidi_t *rmidi;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || !data || switchn < 0)
                return -EINVAL;
+       bzero(data, sizeof(snd_rawmidi_switch_t));
        data->switchn = switchn;
        if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_ISWITCH_READ, data) < 0)
                return -errno;
@@ -237,7 +239,7 @@ int snd_rawmidi_input_switch_write(void *handle, int switchn, snd_rawmidi_switch
        snd_rawmidi_t *rmidi;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || !data || switchn < 0)
                return -EINVAL;
        data->switchn = switchn;
        if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_ISWITCH_WRITE, data) < 0)
@@ -250,7 +252,7 @@ int snd_rawmidi_output_params(void *handle, snd_rawmidi_output_params_t * params
        snd_rawmidi_t *rmidi;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || !params)
                return -EINVAL;
        if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_OUTPUT_PARAMS, params) < 0)
                return -errno;
@@ -262,7 +264,7 @@ int snd_rawmidi_input_params(void *handle, snd_rawmidi_input_params_t * params)
        snd_rawmidi_t *rmidi;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || !params)
                return -EINVAL;
        if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_INPUT_PARAMS, params) < 0)
                return -errno;
@@ -274,7 +276,7 @@ int snd_rawmidi_output_status(void *handle, snd_rawmidi_output_status_t * status
        snd_rawmidi_t *rmidi;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || !status)
                return -EINVAL;
        if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_OUTPUT_STATUS, status) < 0)
                return -errno;
@@ -286,7 +288,7 @@ int snd_rawmidi_input_status(void *handle, snd_rawmidi_input_status_t * status)
        snd_rawmidi_t *rmidi;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || !status)
                return -EINVAL;
        if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_INPUT_STATUS, status) < 0)
                return -errno;
@@ -335,7 +337,7 @@ ssize_t snd_rawmidi_write(void *handle, const void *buffer, size_t size)
        ssize_t result;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || (!buffer && size > 0) || size < 0)
                return -EINVAL;
        result = write(rmidi->fd, buffer, size);
        if (result < 0)
@@ -349,7 +351,7 @@ ssize_t snd_rawmidi_read(void *handle, void *buffer, size_t size)
        ssize_t result;
 
        rmidi = (snd_rawmidi_t *) handle;
-       if (!rmidi)
+       if (!rmidi || (!buffer && size > 0) || size < 0)
                return -EINVAL;
        result = read(rmidi->fd, buffer, size);
        if (result < 0)