mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2026-02-13 04:27:44 -05:00
coverity.com fixes - initial round
This commit tries to fix a bunch of issues found by coverity.com. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
f0679e5de2
commit
47f4f9b73b
40 changed files with 283 additions and 133 deletions
|
|
@ -2580,8 +2580,8 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
|
|||
char *val;
|
||||
if (snd_config_get_id(pcm_conf, &id) < 0)
|
||||
id = NULL;
|
||||
val = NULL;
|
||||
snd_config_get_ascii(pcm_conf, &val);
|
||||
if (snd_config_get_ascii(pcm_conf, &val) < 0)
|
||||
val = NULL;
|
||||
snd_error(PCM, "Invalid type for PCM %s%sdefinition (id: %s, value: %s)", name ? name : "", name ? " " : "", id, val);
|
||||
free(val);
|
||||
return -EINVAL;
|
||||
|
|
@ -3126,7 +3126,7 @@ int snd_pcm_avail_delay(snd_pcm_t *pcm,
|
|||
while (1) {
|
||||
sf = __snd_pcm_avail_update(pcm);
|
||||
if (sf < 0) {
|
||||
err = (int)sf;
|
||||
err = sf < INT_MIN ? -EOVERFLOW : (int)sf;
|
||||
goto unlock;
|
||||
}
|
||||
if (ok && sf == *availp)
|
||||
|
|
@ -3335,6 +3335,8 @@ int snd_pcm_area_copy(const snd_pcm_channel_area_t *dst_area, snd_pcm_uframes_t
|
|||
return 0;
|
||||
dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
|
||||
width = snd_pcm_format_physical_width(format);
|
||||
if (width < 0)
|
||||
return width;
|
||||
if (src_area->step == (unsigned int) width &&
|
||||
dst_area->step == (unsigned int) width) {
|
||||
size_t bytes = samples * width / 8;
|
||||
|
|
@ -7682,8 +7684,7 @@ snd_pcm_sframes_t snd_pcm_read_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_
|
|||
frames = size;
|
||||
if (frames > (snd_pcm_uframes_t) avail)
|
||||
frames = avail;
|
||||
if (! frames)
|
||||
break;
|
||||
/* frames must be at least 1 here (see while condition) */
|
||||
err = func(pcm, areas, offset, frames);
|
||||
if (err < 0)
|
||||
break;
|
||||
|
|
@ -8059,7 +8060,7 @@ void snd_pcm_unlink_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave)
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef DOC_HIDDEN
|
||||
#if !defined(DOC_HIDDEN) && !defined(__COVERITY__)
|
||||
|
||||
#ifdef USE_VERSIONED_SYMBOLS
|
||||
|
||||
|
|
@ -8295,7 +8296,7 @@ OBSOLETE1(snd_pcm_sw_params_get_stop_threshold, ALSA_0.9, ALSA_0.9.0rc4);
|
|||
OBSOLETE1(snd_pcm_sw_params_get_silence_threshold, ALSA_0.9, ALSA_0.9.0rc4);
|
||||
OBSOLETE1(snd_pcm_sw_params_get_silence_size, ALSA_0.9, ALSA_0.9.0rc4);
|
||||
|
||||
#endif /* DOC_HIDDEN */
|
||||
#endif /* DOC_HIDDEN/COVERITY */
|
||||
|
||||
static int chmap_equal(const snd_pcm_chmap_t *a, const snd_pcm_chmap_t *b)
|
||||
{
|
||||
|
|
@ -8794,7 +8795,7 @@ int snd_pcm_recover(snd_pcm_t *pcm, int err, int silent)
|
|||
if (err == -ESTRPIPE) {
|
||||
while ((err = snd_pcm_resume(pcm)) == -EAGAIN)
|
||||
/* wait until suspend flag is released */
|
||||
poll(NULL, 0, 1000);
|
||||
(void)poll(NULL, 0, 1000);
|
||||
if (err < 0) {
|
||||
err = snd_pcm_prepare(pcm);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -1763,7 +1763,11 @@ int snd_pcm_direct_parse_bindings(snd_pcm_direct_t *dmix,
|
|||
long cchannel, schannel;
|
||||
if (snd_config_get_id(n, &id) < 0)
|
||||
continue;
|
||||
safe_strtol(id, &cchannel);
|
||||
err = safe_strtol(id, &cchannel);
|
||||
if (err < 0) {
|
||||
free(bindings);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (snd_config_get_integer(n, &schannel) < 0) {
|
||||
snd_error(PCM, "unable to get slave channel (should be integer type) in binding: %s", id);
|
||||
free(bindings);
|
||||
|
|
@ -1907,6 +1911,14 @@ static int _snd_pcm_direct_get_slave_ipc_offset(snd_config_t *root,
|
|||
device = 0;
|
||||
if (subdevice < 0)
|
||||
subdevice = 0;
|
||||
if (card < 0 || card >= (1 << (31 - 12 - 1)))
|
||||
return -EOVERFLOW;
|
||||
if (device >= (1 << 6))
|
||||
return -EOVERFLOW;
|
||||
if (subdevice >= (1 << 4))
|
||||
return -EOVERFLOW;
|
||||
if (direction < 0 || direction > 1)
|
||||
return -EOVERFLOW;
|
||||
return (direction << 1) + (device << 2) + (subdevice << 8) + (card << 12);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,13 +69,19 @@
|
|||
static void mix_select_callbacks(snd_pcm_direct_t *dmix)
|
||||
{
|
||||
static int smp = 0;
|
||||
unsigned int format = dmix->shmptr->s.format;
|
||||
|
||||
if (!dmix->direct_memory_access) {
|
||||
generic_mix_select_callbacks(dmix);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!((1ULL<< dmix->shmptr->s.format) & x86_64_dmix_supported_format)) {
|
||||
if (format > 31) {
|
||||
generic_mix_select_callbacks(dmix);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!((1U << format) & x86_64_dmix_supported_format)) {
|
||||
generic_mix_select_callbacks(dmix);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,12 @@ static void share_areas(snd_pcm_direct_t *dshare,
|
|||
channels = dshare->channels;
|
||||
format = dshare->shmptr->s.format;
|
||||
if (dshare->interleaved) {
|
||||
unsigned int fbytes = snd_pcm_format_physical_width(format) / 8;
|
||||
int width = snd_pcm_format_physical_width(format);
|
||||
unsigned int fbytes;
|
||||
|
||||
if (width < 0)
|
||||
return;
|
||||
fbytes = width / 8;
|
||||
memcpy(((char *)dst_areas[0].addr) + (dst_ofs * channels * fbytes),
|
||||
((char *)src_areas[0].addr) + (src_ofs * channels * fbytes),
|
||||
size * channels * fbytes);
|
||||
|
|
|
|||
|
|
@ -81,11 +81,16 @@ static void snoop_areas(snd_pcm_direct_t *dsnoop,
|
|||
{
|
||||
unsigned int chn, schn, channels;
|
||||
snd_pcm_format_t format;
|
||||
unsigned int fbytes;
|
||||
int pwidth;
|
||||
|
||||
channels = dsnoop->channels;
|
||||
format = dsnoop->shmptr->s.format;
|
||||
if (dsnoop->interleaved) {
|
||||
unsigned int fbytes = snd_pcm_format_physical_width(format) / 8;
|
||||
pwidth = snd_pcm_format_physical_width(format);
|
||||
if (pwidth < 0)
|
||||
return;
|
||||
fbytes = pwidth / 8;
|
||||
memcpy(((char *)dst_areas[0].addr) + (dst_ofs * channels * fbytes),
|
||||
((char *)src_areas[0].addr) + (src_ofs * channels * fbytes),
|
||||
size * channels * fbytes);
|
||||
|
|
|
|||
|
|
@ -467,7 +467,12 @@ static int snd_pcm_file_add_frames(snd_pcm_t *pcm,
|
|||
int err = 0;
|
||||
snd_pcm_uframes_t n = frames;
|
||||
snd_pcm_uframes_t cont = file->wbuf_size - file->appl_ptr;
|
||||
snd_pcm_uframes_t avail = file->wbuf_size - snd_pcm_bytes_to_frames(pcm, file->wbuf_used_bytes);
|
||||
snd_pcm_sframes_t used = snd_pcm_bytes_to_frames(pcm, file->wbuf_used_bytes);
|
||||
snd_pcm_uframes_t avail;
|
||||
|
||||
if (used < 0)
|
||||
return used;
|
||||
avail = file->wbuf_size - used;
|
||||
if (n > cont)
|
||||
n = cont;
|
||||
if (n > avail)
|
||||
|
|
@ -475,12 +480,15 @@ static int snd_pcm_file_add_frames(snd_pcm_t *pcm,
|
|||
snd_pcm_areas_copy(file->wbuf_areas, file->appl_ptr,
|
||||
areas, offset,
|
||||
pcm->channels, n, pcm->format);
|
||||
used = snd_pcm_frames_to_bytes(pcm, n);
|
||||
if (used < 0)
|
||||
return used;
|
||||
frames -= n;
|
||||
offset += n;
|
||||
file->appl_ptr += n;
|
||||
if (file->appl_ptr == file->wbuf_size)
|
||||
file->appl_ptr = 0;
|
||||
file->wbuf_used_bytes += snd_pcm_frames_to_bytes(pcm, n);
|
||||
file->wbuf_used_bytes += used;
|
||||
if (file->wbuf_used_bytes > file->buffer_bytes) {
|
||||
err = snd_pcm_file_write_bytes(pcm, file->wbuf_used_bytes - file->buffer_bytes);
|
||||
if (err < 0)
|
||||
|
|
@ -562,16 +570,23 @@ static snd_pcm_sframes_t snd_pcm_file_rewindable(snd_pcm_t *pcm)
|
|||
static snd_pcm_sframes_t snd_pcm_file_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private_data;
|
||||
snd_pcm_sframes_t err;
|
||||
snd_pcm_uframes_t n;
|
||||
snd_pcm_sframes_t err, n;
|
||||
|
||||
n = snd_pcm_frames_to_bytes(pcm, frames);
|
||||
if (n > file->wbuf_used_bytes)
|
||||
frames = snd_pcm_bytes_to_frames(pcm, file->wbuf_used_bytes);
|
||||
if (n < 0)
|
||||
return n;
|
||||
if ((size_t)n > file->wbuf_used_bytes) {
|
||||
err = snd_pcm_bytes_to_frames(pcm, file->wbuf_used_bytes);
|
||||
if (err < 0)
|
||||
return err;
|
||||
frames = err;
|
||||
}
|
||||
err = snd_pcm_rewind(file->gen.slave, frames);
|
||||
if (err > 0) {
|
||||
file->appl_ptr = (file->appl_ptr - err + file->wbuf_size) % file->wbuf_size;
|
||||
n = snd_pcm_frames_to_bytes(pcm, err);
|
||||
if (n < 0)
|
||||
return n;
|
||||
file->appl_ptr = (file->appl_ptr - err + file->wbuf_size) % file->wbuf_size;
|
||||
file->wbuf_used_bytes -= n;
|
||||
}
|
||||
return err;
|
||||
|
|
@ -582,6 +597,8 @@ static snd_pcm_sframes_t snd_pcm_file_forwardable(snd_pcm_t *pcm)
|
|||
snd_pcm_file_t *file = pcm->private_data;
|
||||
snd_pcm_sframes_t res = snd_pcm_forwardable(file->gen.slave);
|
||||
snd_pcm_sframes_t n = snd_pcm_bytes_to_frames(pcm, file->wbuf_size_bytes - file->wbuf_used_bytes);
|
||||
if (n < 0)
|
||||
return n;
|
||||
if (res > n)
|
||||
res = n;
|
||||
return res;
|
||||
|
|
@ -590,16 +607,23 @@ static snd_pcm_sframes_t snd_pcm_file_forwardable(snd_pcm_t *pcm)
|
|||
static snd_pcm_sframes_t snd_pcm_file_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private_data;
|
||||
snd_pcm_sframes_t err;
|
||||
snd_pcm_uframes_t n;
|
||||
snd_pcm_sframes_t err, n;
|
||||
|
||||
n = snd_pcm_frames_to_bytes(pcm, frames);
|
||||
if (file->wbuf_used_bytes + n > file->wbuf_size_bytes)
|
||||
frames = snd_pcm_bytes_to_frames(pcm, file->wbuf_size_bytes - file->wbuf_used_bytes);
|
||||
if (n < 0)
|
||||
return n;
|
||||
if (file->wbuf_used_bytes + n > file->wbuf_size_bytes) {
|
||||
err = snd_pcm_bytes_to_frames(pcm, file->wbuf_size_bytes - file->wbuf_used_bytes);
|
||||
if (err < 0)
|
||||
return err;
|
||||
frames = err;
|
||||
}
|
||||
err = INTERNAL(snd_pcm_forward)(file->gen.slave, frames);
|
||||
if (err > 0) {
|
||||
file->appl_ptr = (file->appl_ptr + err) % file->wbuf_size;
|
||||
n = snd_pcm_frames_to_bytes(pcm, err);
|
||||
if (n < 0)
|
||||
return err;
|
||||
file->appl_ptr = (file->appl_ptr + err) % file->wbuf_size;
|
||||
file->wbuf_used_bytes += n;
|
||||
}
|
||||
return err;
|
||||
|
|
@ -755,10 +779,14 @@ static int snd_pcm_file_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
|
|||
snd_pcm_file_t *file = pcm->private_data;
|
||||
unsigned int channel;
|
||||
snd_pcm_t *slave = file->gen.slave;
|
||||
snd_pcm_sframes_t bsize;
|
||||
int err = _snd_pcm_hw_params_internal(slave, params);
|
||||
if (err < 0)
|
||||
return err;
|
||||
file->buffer_bytes = snd_pcm_frames_to_bytes(slave, slave->buffer_size);
|
||||
bsize = snd_pcm_frames_to_bytes(slave, slave->buffer_size);
|
||||
if (bsize < 0)
|
||||
return bsize;
|
||||
file->buffer_bytes = bsize;
|
||||
file->wbuf_size = slave->buffer_size * 2;
|
||||
file->wbuf_size_bytes = snd_pcm_frames_to_bytes(slave, file->wbuf_size);
|
||||
file->wbuf_used_bytes = 0;
|
||||
|
|
@ -932,14 +960,21 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
|
|||
file->perm = perm;
|
||||
|
||||
if (ifname && (stream == SND_PCM_STREAM_CAPTURE)) {
|
||||
ifd = open(ifname, O_RDONLY); /* TODO: mind blocking mode */
|
||||
if (ifd < 0) {
|
||||
file->ifname = strdup(ifname);
|
||||
if (file->ifname)
|
||||
ifd = open(ifname, O_RDONLY); /* TODO: mind blocking mode */
|
||||
else
|
||||
ifd = -1;
|
||||
if (ifd < 0 || file->ifname == NULL) {
|
||||
if (ifd >= 0)
|
||||
close(ifd);
|
||||
err = -errno;
|
||||
snd_errornum(PCM, "open %s for reading failed", ifname);
|
||||
free(file->ifname);
|
||||
free(file->fname);
|
||||
free(file);
|
||||
return -errno;
|
||||
return err;
|
||||
}
|
||||
file->ifname = strdup(ifname);
|
||||
}
|
||||
file->fd = fd;
|
||||
file->ifd = ifd;
|
||||
|
|
@ -949,6 +984,8 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
|
|||
|
||||
err = snd_pcm_new(&pcm, SND_PCM_TYPE_FILE, name, slave->stream, slave->mode);
|
||||
if (err < 0) {
|
||||
if (file->ifname && file->ifd >= 0)
|
||||
close(file->ifd);
|
||||
free(file->fname);
|
||||
free(file->ifname);
|
||||
free(file);
|
||||
|
|
|
|||
|
|
@ -469,8 +469,8 @@ static int snd_pcm_hw_change_timer(snd_pcm_t *pcm, int enable)
|
|||
*/
|
||||
{
|
||||
int ver = 0;
|
||||
ioctl(hw->period_timer_pfd.fd,
|
||||
SNDRV_TIMER_IOCTL_PVERSION, &ver);
|
||||
if (ioctl(hw->period_timer_pfd.fd, SNDRV_TIMER_IOCTL_PVERSION, &ver))
|
||||
snd_warn(PCM, "unable to get protocol version");
|
||||
/*
|
||||
* In older versions, check via poll before read() is
|
||||
* needed because of the confliction between
|
||||
|
|
|
|||
|
|
@ -891,7 +891,7 @@ snd_pcm_ladspa_write_areas(snd_pcm_t *pcm,
|
|||
chn = instance->output.channels.array[idx];
|
||||
data = instance->output.data[idx];
|
||||
if (data == NULL) {
|
||||
data = (LADSPA_Data *)((char *)slave_areas[chn].addr + (areas[chn].first / 8));
|
||||
data = (LADSPA_Data *)((char *)slave_areas[chn].addr + (slave_areas[chn].first / 8));
|
||||
data += slave_offset;
|
||||
}
|
||||
instance->desc->connect_port(instance->handle, instance->output.ports.array[idx], data);
|
||||
|
|
@ -943,7 +943,7 @@ snd_pcm_ladspa_read_areas(snd_pcm_t *pcm,
|
|||
chn = instance->input.channels.array[idx];
|
||||
data = instance->input.data[idx];
|
||||
if (data == NULL) {
|
||||
data = (LADSPA_Data *)((char *)slave_areas[chn].addr + (areas[chn].first / 8));
|
||||
data = (LADSPA_Data *)((char *)slave_areas[chn].addr + (slave_areas[chn].first / 8));
|
||||
data += slave_offset;
|
||||
}
|
||||
instance->desc->connect_port(instance->handle, instance->input.ports.array[idx], data);
|
||||
|
|
@ -1759,7 +1759,9 @@ int _snd_pcm_ladspa_open(snd_pcm_t **pcmp, const char *name,
|
|||
continue;
|
||||
}
|
||||
if (strcmp(id, "channels") == 0) {
|
||||
snd_config_get_integer(n, &channels);
|
||||
err = snd_config_get_integer(n, &channels);
|
||||
if (err < 0)
|
||||
return err;
|
||||
if (channels > 1024)
|
||||
channels = 1024;
|
||||
if (channels < 0)
|
||||
|
|
|
|||
|
|
@ -443,7 +443,7 @@ static int snd_pcm_meter_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
|
|||
snd_pcm_meter_t *meter = pcm->private_data;
|
||||
unsigned int channel;
|
||||
snd_pcm_t *slave = meter->gen.slave;
|
||||
size_t buf_size_bytes;
|
||||
ssize_t buf_size_bytes;
|
||||
int err;
|
||||
err = snd_pcm_hw_params_slave(pcm, params,
|
||||
snd_pcm_meter_hw_refine_cchange,
|
||||
|
|
@ -457,6 +457,8 @@ static int snd_pcm_meter_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
|
|||
while (meter->buf_size < slave->rate)
|
||||
meter->buf_size *= 2;
|
||||
buf_size_bytes = snd_pcm_frames_to_bytes(slave, meter->buf_size);
|
||||
if (buf_size_bytes < 0)
|
||||
return buf_size_bytes;
|
||||
assert(!meter->buf);
|
||||
meter->buf = malloc(buf_size_bytes);
|
||||
if (!meter->buf)
|
||||
|
|
|
|||
|
|
@ -619,12 +619,12 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
|
|||
break;
|
||||
}
|
||||
case 8: {
|
||||
uint8_t silence = snd_pcm_format_silence_64(format);
|
||||
uint8_t silence = snd_pcm_format_silence(format);
|
||||
memset(data, silence, samples);
|
||||
break;
|
||||
}
|
||||
case 16: {
|
||||
uint16_t silence = snd_pcm_format_silence_64(format);
|
||||
uint16_t silence = snd_pcm_format_silence_16(format);
|
||||
uint16_t *pdata = (uint16_t *)data;
|
||||
if (! silence)
|
||||
memset(data, 0, samples * 2);
|
||||
|
|
@ -635,7 +635,7 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
|
|||
break;
|
||||
}
|
||||
case 24: {
|
||||
uint32_t silence = snd_pcm_format_silence_64(format);
|
||||
uint32_t silence = snd_pcm_format_silence_32(format);
|
||||
uint8_t *pdata = (uint8_t *)data;
|
||||
if (! silence)
|
||||
memset(data, 0, samples * 3);
|
||||
|
|
@ -655,7 +655,7 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
|
|||
break;
|
||||
}
|
||||
case 32: {
|
||||
uint32_t silence = snd_pcm_format_silence_64(format);
|
||||
uint32_t silence = snd_pcm_format_silence_32(format);
|
||||
uint32_t *pdata = (uint32_t *)data;
|
||||
if (! silence)
|
||||
memset(data, 0, samples * 4);
|
||||
|
|
|
|||
|
|
@ -251,6 +251,8 @@ static int snd_pcm_mulaw_hw_refine_cprepare(snd_pcm_t *pcm, snd_pcm_hw_params_t
|
|||
err = _snd_pcm_hw_params_set_format(params,
|
||||
SND_PCM_FORMAT_MU_LAW);
|
||||
}
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = _snd_pcm_hw_params_set_subformat(params, SND_PCM_SUBFORMAT_STD);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
|
|
|||
|
|
@ -1439,13 +1439,13 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
|
|||
_free:
|
||||
if (err < 0) {
|
||||
for (idx = 0; idx < slaves_count; ++idx) {
|
||||
if (slaves_pcm[idx])
|
||||
if (slaves_pcm && slaves_pcm[idx])
|
||||
snd_pcm_close(slaves_pcm[idx]);
|
||||
}
|
||||
}
|
||||
if (slaves_conf) {
|
||||
for (idx = 0; idx < slaves_count; ++idx) {
|
||||
if (slaves_conf[idx])
|
||||
if (slaves_conf && slaves_conf[idx])
|
||||
snd_config_delete(slaves_conf[idx]);
|
||||
}
|
||||
free(slaves_conf);
|
||||
|
|
|
|||
|
|
@ -967,6 +967,8 @@ static int snd_pcm_hw_param_set_near_minmax(snd_pcm_t *pcm,
|
|||
if (boundary_lt(min, *mindir, max, *maxdir)) {
|
||||
tmp = *params;
|
||||
err = snd_pcm_hw_param_set_near(pcm, &tmp, var, &max, maxdir);
|
||||
if (err < 0)
|
||||
return err;
|
||||
} else {
|
||||
max = min;
|
||||
*maxdir = *mindir;
|
||||
|
|
|
|||
|
|
@ -235,6 +235,8 @@ static const char linear_format_widths[32] = {
|
|||
static int check_linear_format(const snd_pcm_format_mask_t *format_mask, int wid, int sgn, int ed)
|
||||
{
|
||||
int e, s;
|
||||
if (wid < 1 || wid > 32)
|
||||
return SND_PCM_FORMAT_UNKNOWN;
|
||||
if (! linear_format_widths[wid - 1])
|
||||
return SND_PCM_FORMAT_UNKNOWN;
|
||||
for (e = 0; e < 2; e++) {
|
||||
|
|
@ -450,13 +452,15 @@ static int snd_pcm_plug_change_channels(snd_pcm_t *pcm, snd_pcm_t **new, snd_pcm
|
|||
snd_pcm_route_ttable_entry_t v = SND_PCM_PLUGIN_ROUTE_FULL;
|
||||
if (rpolicy == PLUG_ROUTE_POLICY_AVERAGE) {
|
||||
if (pcm->stream == SND_PCM_STREAM_PLAYBACK &&
|
||||
clt->channels > slv->channels) {
|
||||
clt->channels > slv->channels &&
|
||||
slv->channels > 0) {
|
||||
int srcs = clt->channels / slv->channels;
|
||||
if (s < clt->channels % slv->channels)
|
||||
srcs++;
|
||||
v /= srcs;
|
||||
} else if (pcm->stream == SND_PCM_STREAM_CAPTURE &&
|
||||
slv->channels > clt->channels) {
|
||||
slv->channels > clt->channels &&
|
||||
clt->channels > 0) {
|
||||
int srcs = slv->channels / clt->channels;
|
||||
if (s < slv->channels % clt->channels)
|
||||
srcs++;
|
||||
|
|
@ -1338,6 +1342,7 @@ int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
|
|||
SND_PCM_HW_PARAM_RATE, SCONF_UNCHANGED, &srate);
|
||||
if (err < 0)
|
||||
return err;
|
||||
csize = ssize = cused = sused = 0;
|
||||
#ifdef BUILD_PCM_PLUGIN_ROUTE
|
||||
if (tt) {
|
||||
err = snd_pcm_route_determine_ttable(tt, &csize, &ssize);
|
||||
|
|
@ -1352,6 +1357,7 @@ int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
|
|||
}
|
||||
err = snd_pcm_route_load_ttable(tt, ttable, csize, ssize, &cused, &sused, -1);
|
||||
if (err < 0) {
|
||||
free(ttable);
|
||||
snd_config_delete(sconf);
|
||||
return err;
|
||||
}
|
||||
|
|
@ -1365,8 +1371,10 @@ int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
|
|||
|
||||
err = snd_pcm_open_slave(&spcm, root, sconf, stream, mode, conf);
|
||||
snd_config_delete(sconf);
|
||||
if (err < 0)
|
||||
if (err < 0) {
|
||||
free(ttable);
|
||||
return err;
|
||||
}
|
||||
err = snd_pcm_plug_open(pcmp, name, sformat, schannels, srate, rate_converter,
|
||||
route_policy, ttable, ssize, cused, sused, spcm, 1);
|
||||
if (err < 0)
|
||||
|
|
|
|||
|
|
@ -88,6 +88,12 @@ rate_alloc_tmp_buf(snd_pcm_format_t format,
|
|||
int width = snd_pcm_format_physical_width(format);
|
||||
unsigned int i;
|
||||
|
||||
if (width < 0 || width > 128)
|
||||
return NULL;
|
||||
if (channels > 1024)
|
||||
return NULL;
|
||||
if (frames > 10*1024*1024)
|
||||
return NULL;
|
||||
ap = malloc(sizeof(*ap) * channels);
|
||||
if (!ap)
|
||||
return NULL;
|
||||
|
|
@ -320,6 +326,9 @@ static int choose_preferred_format(snd_pcm_rate_t *rate)
|
|||
if (!in_mask || !out_mask)
|
||||
return 0;
|
||||
|
||||
if (rate->orig_in_format < 0 || rate->orig_in_format > 63)
|
||||
return -EINVAL;
|
||||
|
||||
if (rate->orig_in_format == rate->orig_out_format)
|
||||
if (in_mask & out_mask & (1ULL << rate->orig_in_format))
|
||||
return 0; /* nothing changed */
|
||||
|
|
|
|||
|
|
@ -1339,6 +1339,7 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
|
|||
continue;
|
||||
}
|
||||
snd_error(PCM, "Unknown field %s", id);
|
||||
snd_pcm_free_chmaps(chmaps);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!slave) {
|
||||
|
|
@ -1368,7 +1369,8 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
|
|||
|
||||
err = determine_chmap(tt, &tt_chmap);
|
||||
if (err < 0) {
|
||||
free(ttable);
|
||||
snd_config_delete(sconf);
|
||||
snd_pcm_free_chmaps(chmaps);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -1376,7 +1378,6 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
|
|||
snd_config_delete(sconf);
|
||||
if (err < 0) {
|
||||
free(tt_chmap);
|
||||
free(ttable);
|
||||
snd_pcm_free_chmaps(chmaps);
|
||||
return err;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -288,7 +288,7 @@ static snd_pcm_uframes_t _snd_pcm_share_missing(snd_pcm_t *pcm)
|
|||
|
||||
update_poll:
|
||||
if (ready != share->ready) {
|
||||
char buf[1];
|
||||
char buf[1] = {0};
|
||||
while (1) {
|
||||
if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
|
||||
if (ready)
|
||||
|
|
@ -366,14 +366,15 @@ static void *snd_pcm_share_thread(void *data)
|
|||
struct pollfd pfd[2];
|
||||
int err;
|
||||
|
||||
Pthread_mutex_lock(&slave->mutex);
|
||||
pfd[0].fd = slave->poll[0];
|
||||
pfd[0].events = POLLIN;
|
||||
err = snd_pcm_poll_descriptors(spcm, &pfd[1], 1);
|
||||
if (err != 1) {
|
||||
snd_error(PCM, "invalid poll descriptors %d", err);
|
||||
Pthread_mutex_unlock(&slave->mutex);
|
||||
return NULL;
|
||||
}
|
||||
Pthread_mutex_lock(&slave->mutex);
|
||||
err = pipe(slave->poll);
|
||||
if (err < 0) {
|
||||
snd_errornum(PCM, "can't create a pipe");
|
||||
|
|
@ -412,9 +413,9 @@ static void *snd_pcm_share_thread(void *data)
|
|||
Pthread_mutex_unlock(&slave->mutex);
|
||||
err = poll(pfd, 2, -1);
|
||||
Pthread_mutex_lock(&slave->mutex);
|
||||
if (pfd[0].revents & POLLIN) {
|
||||
if (err > 0 && (pfd[0].revents & POLLIN) != 0) {
|
||||
char buf[1];
|
||||
read(pfd[0].fd, buf, 1);
|
||||
(void)read(pfd[0].fd, buf, 1);
|
||||
}
|
||||
} else {
|
||||
slave->polling = 0;
|
||||
|
|
@ -931,9 +932,12 @@ static int snd_pcm_share_start(snd_pcm_t *pcm)
|
|||
snd_pcm_share_slave_t *slave = share->slave;
|
||||
snd_pcm_t *spcm = slave->pcm;
|
||||
int err = 0;
|
||||
if (share->state != SND_PCM_STATE_PREPARED)
|
||||
return -EBADFD;
|
||||
|
||||
Pthread_mutex_lock(&slave->mutex);
|
||||
if (share->state != SND_PCM_STATE_PREPARED) {
|
||||
err = -EBADFD;
|
||||
goto _end;
|
||||
}
|
||||
share->state = SND_PCM_STATE_RUNNING;
|
||||
if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
|
||||
snd_pcm_uframes_t hw_avail = snd_pcm_mmap_playback_hw_avail(pcm);
|
||||
|
|
@ -1152,8 +1156,13 @@ static void _snd_pcm_share_stop(snd_pcm_t *pcm, snd_pcm_state_t state)
|
|||
snd_pcm_areas_silence(pcm->running_areas, 0, pcm->channels,
|
||||
pcm->buffer_size, pcm->format);
|
||||
err = snd_pcm_delay(slave->pcm, &delay);
|
||||
if (err >= 0 && delay > 0)
|
||||
snd_pcm_rewind(slave->pcm, delay);
|
||||
if (err >= 0 && delay > 0) {
|
||||
int err = snd_pcm_rewind(slave->pcm, delay);
|
||||
if (err < 0) {
|
||||
errno = -err;
|
||||
snd_errornum(PCM, "rewind failed");
|
||||
}
|
||||
}
|
||||
share->drain_silenced = 0;
|
||||
}
|
||||
share->state = state;
|
||||
|
|
@ -1444,7 +1453,7 @@ int snd_pcm_share_open(snd_pcm_t **pcmp, const char *name, const char *sname,
|
|||
pfd.fd = sd[0];
|
||||
pfd.events = POLLOUT;
|
||||
while ((err = poll(&pfd, 1, 0)) == 1) {
|
||||
char buf[1];
|
||||
char buf[1] = {0};
|
||||
err = write(sd[0], buf, 1);
|
||||
assert(err != 0);
|
||||
if (err != 1)
|
||||
|
|
|
|||
|
|
@ -323,8 +323,6 @@ static int snd_pcm_shm_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t * params)
|
|||
ctrl->u.sw_params = *params;
|
||||
err = snd_pcm_shm_action(pcm);
|
||||
*params = ctrl->u.sw_params;
|
||||
if (err < 0)
|
||||
return err;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -437,8 +435,6 @@ static snd_pcm_sframes_t snd_pcm_shm_avail_update(snd_pcm_t *pcm)
|
|||
int err;
|
||||
ctrl->cmd = SND_PCM_IOCTL_AVAIL_UPDATE;
|
||||
err = snd_pcm_shm_action(pcm);
|
||||
if (err < 0)
|
||||
return err;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -637,7 +633,7 @@ static int make_local_socket(const char *filename)
|
|||
size_t l = strlen(filename);
|
||||
size_t size = offsetof(struct sockaddr_un, sun_path) + l;
|
||||
struct sockaddr_un *addr = alloca(size);
|
||||
int sock;
|
||||
int sock, err;
|
||||
|
||||
sock = socket(PF_LOCAL, SOCK_STREAM, 0);
|
||||
if (sock < 0) {
|
||||
|
|
@ -649,8 +645,10 @@ static int make_local_socket(const char *filename)
|
|||
memcpy(addr->sun_path, filename, l);
|
||||
|
||||
if (connect(sock, (struct sockaddr *) addr, size) < 0) {
|
||||
err = -errno;
|
||||
snd_errornum(PCM, "connect failed");
|
||||
return -errno;
|
||||
close(sock);
|
||||
return err;
|
||||
}
|
||||
return sock;
|
||||
}
|
||||
|
|
@ -722,6 +720,11 @@ int snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
|
|||
result = -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
if (ans.result < INT_MIN || ans.result > INT_MAX) {
|
||||
snd_error(PCM, "invalid read");
|
||||
result = -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
result = ans.result;
|
||||
if (result < 0)
|
||||
goto _err;
|
||||
|
|
@ -764,7 +767,8 @@ int snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
|
|||
return 0;
|
||||
|
||||
_err:
|
||||
close(sock);
|
||||
if (sock >= 0)
|
||||
close(sock);
|
||||
if (ctrl)
|
||||
shmdt(ctrl);
|
||||
free(shm);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue