sink-input, source-output: fix uninitialized variable access

The volume_map variable was initialized only for PCM streams, but the
variable was passed to pa_cvolume_remap() also for non-PCM streams. The
volume remapping is never necessary for passthrough streams (PCM or
not), because no volume will be applied anyway, so let's skip the
pa_cvolume_remap() call for all passthrough streams.
This commit is contained in:
Tanu Kaskinen 2018-05-05 16:53:04 +03:00
parent 9e5be0899f
commit ad14bdb240
2 changed files with 12 additions and 4 deletions

View file

@ -364,7 +364,7 @@ int pa_sink_input_new(
/* Routing is done. We have a sink and a format. */ /* Routing is done. We have a sink and a format. */
if (data->volume_is_set && pa_format_info_is_pcm(data->format)) { if (data->volume_is_set && !pa_sink_input_new_data_is_passthrough(data)) {
/* If volume is set, we need to save the original data->channel_map, /* If volume is set, we need to save the original data->channel_map,
* so that we can remap the volume from the original channel map to the * so that we can remap the volume from the original channel map to the
* final channel map of the stream in case data->channel_map gets * final channel map of the stream in case data->channel_map gets
@ -372,6 +372,10 @@ int pa_sink_input_new(
r = pa_stream_get_volume_channel_map(&data->volume, data->channel_map_is_set ? &data->channel_map : NULL, data->format, &volume_map); r = pa_stream_get_volume_channel_map(&data->volume, data->channel_map_is_set ? &data->channel_map : NULL, data->format, &volume_map);
if (r < 0) if (r < 0)
return r; return r;
} else {
/* Initialize volume_map to invalid state. We check the state later to
* determine if volume remapping is needed. */
pa_channel_map_init(&volume_map);
} }
/* Now populate the sample spec and channel map according to the final /* Now populate the sample spec and channel map according to the final
@ -403,7 +407,7 @@ int pa_sink_input_new(
if (!data->volume_writable) if (!data->volume_writable)
data->save_volume = false; data->save_volume = false;
if (data->volume_is_set) if (pa_channel_map_valid(&volume_map))
/* The original volume channel map may be different than the final /* The original volume channel map may be different than the final
* stream channel map, so remapping may be needed. */ * stream channel map, so remapping may be needed. */
pa_cvolume_remap(&data->volume, &volume_map, &data->channel_map); pa_cvolume_remap(&data->volume, &volume_map, &data->channel_map);

View file

@ -306,7 +306,7 @@ int pa_source_output_new(
/* Routing is done. We have a source and a format. */ /* Routing is done. We have a source and a format. */
if (data->volume_is_set && pa_format_info_is_pcm(data->format)) { if (data->volume_is_set && !pa_source_output_new_data_is_passthrough(data)) {
/* If volume is set, we need to save the original data->channel_map, /* If volume is set, we need to save the original data->channel_map,
* so that we can remap the volume from the original channel map to the * so that we can remap the volume from the original channel map to the
* final channel map of the stream in case data->channel_map gets * final channel map of the stream in case data->channel_map gets
@ -314,6 +314,10 @@ int pa_source_output_new(
r = pa_stream_get_volume_channel_map(&data->volume, data->channel_map_is_set ? &data->channel_map : NULL, data->format, &volume_map); r = pa_stream_get_volume_channel_map(&data->volume, data->channel_map_is_set ? &data->channel_map : NULL, data->format, &volume_map);
if (r < 0) if (r < 0)
return r; return r;
} else {
/* Initialize volume_map to invalid state. We check the state later to
* determine if volume remapping is needed. */
pa_channel_map_init(&volume_map);
} }
/* Now populate the sample spec and channel map according to the final /* Now populate the sample spec and channel map according to the final
@ -341,7 +345,7 @@ int pa_source_output_new(
if (!data->volume_writable) if (!data->volume_writable)
data->save_volume = false; data->save_volume = false;
if (data->volume_is_set) if (pa_channel_map_valid(&volume_map))
/* The original volume channel map may be different than the final /* The original volume channel map may be different than the final
* stream channel map, so remapping may be needed. */ * stream channel map, so remapping may be needed. */
pa_cvolume_remap(&data->volume, &volume_map, &data->channel_map); pa_cvolume_remap(&data->volume, &volume_map, &data->channel_map);