mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
handle snprintf errors better
This commit is contained in:
parent
99b1ce96ed
commit
8184d4576a
2 changed files with 18 additions and 7 deletions
|
|
@ -410,20 +410,28 @@ spa_alsa_enum_format(struct state *state, int seq, uint32_t start, uint32_t num,
|
|||
}
|
||||
if (j == 0) {
|
||||
char buf[1024];
|
||||
int i, offs;
|
||||
int i, r, offs;
|
||||
|
||||
for (i = 0, offs = 0; i <= SND_PCM_FORMAT_LAST; i++) {
|
||||
if (snd_pcm_format_mask_test(fmask, (snd_pcm_format_t)i))
|
||||
offs += snprintf(&buf[offs], sizeof(buf) - offs,
|
||||
if (snd_pcm_format_mask_test(fmask, (snd_pcm_format_t)i)) {
|
||||
r = snprintf(&buf[offs], sizeof(buf) - offs,
|
||||
"%s ", snd_pcm_format_name((snd_pcm_format_t)i));
|
||||
if (r < 0 || r + offs >= (int)sizeof(buf))
|
||||
return -ENOSPC;
|
||||
offs += r;
|
||||
}
|
||||
}
|
||||
spa_log_warn(state->log, "%s: unsupported card: formats:%s",
|
||||
state->props.device, buf);
|
||||
|
||||
for (i = 0, offs = 0; i <= SND_PCM_ACCESS_LAST; i++) {
|
||||
if (snd_pcm_access_mask_test(amask, (snd_pcm_access_t)i))
|
||||
offs += snprintf(&buf[offs], sizeof(buf) - offs,
|
||||
if (snd_pcm_access_mask_test(amask, (snd_pcm_access_t)i)) {
|
||||
r = snprintf(&buf[offs], sizeof(buf) - offs,
|
||||
"%s ", snd_pcm_access_name((snd_pcm_access_t)i));
|
||||
if (r < 0 || r + offs >= (int)sizeof(buf))
|
||||
return -ENOSPC;
|
||||
offs += r;
|
||||
}
|
||||
}
|
||||
spa_log_warn(state->log, "%s: unsupported card: access:%s",
|
||||
state->props.device, buf);
|
||||
|
|
|
|||
|
|
@ -455,12 +455,15 @@ int format_info_from_spec(struct format_info *info, struct sample_spec *ss,
|
|||
pw_properties_setf(info->props, "format.channels", "%d", ss->channels);
|
||||
if (map && map->channels == ss->channels) {
|
||||
char chmap[1024] = "";
|
||||
int i, o;
|
||||
int i, o, r;
|
||||
uint32_t aux = 0;
|
||||
|
||||
for (i = 0, o = 0; i < map->channels; i++) {
|
||||
o += snprintf(chmap+o, sizeof(chmap)-o, "%s%s", i == 0 ? "" : ",",
|
||||
r = snprintf(chmap+o, sizeof(chmap)-o, "%s%s", i == 0 ? "" : ",",
|
||||
channel_id2paname(map->map[i], &aux));
|
||||
if (r < 0 || o + r >= (int)sizeof(chmap))
|
||||
return -ENOSPC;
|
||||
o += r;
|
||||
}
|
||||
pw_properties_setf(info->props, "format.channel_map", "\"%s\"", chmap);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue