summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_coreaudio_chmap.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-10-26 15:51:59 +0100
committerwm4 <wm4@nowhere>2015-10-26 15:51:59 +0100
commit72d3c5ef00a71f4620279e0883c86894f145939d (patch)
treed4c2e1a1ad10a114fdd56ba26b06f4e2308fc854 /audio/out/ao_coreaudio_chmap.c
parent81109dcbb6093f7c4298a1c677a2d06cea5107d8 (diff)
downloadmpv-72d3c5ef00a71f4620279e0883c86894f145939d.tar.bz2
mpv-72d3c5ef00a71f4620279e0883c86894f145939d.tar.xz
ao_coreaudio: fix potential UB in error cases
mNumberChannelDescriptions being 0 is pretty much an error, but if it can happen, then the code checking the chmap below will trigger UB, as chmap is not initialized at all. Also, simplify the code a little: we never change the number of channels, so this is just fine.
Diffstat (limited to 'audio/out/ao_coreaudio_chmap.c')
-rw-r--r--audio/out/ao_coreaudio_chmap.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/audio/out/ao_coreaudio_chmap.c b/audio/out/ao_coreaudio_chmap.c
index 52ea81d5c7..df6b188656 100644
--- a/audio/out/ao_coreaudio_chmap.c
+++ b/audio/out/ao_coreaudio_chmap.c
@@ -151,6 +151,7 @@ static bool ca_layout_to_mp_chmap(struct ao *ao, AudioChannelLayout *layout,
return false;
}
+ chmap->num = l->mNumberChannelDescriptions;
for (int n = 0; n < l->mNumberChannelDescriptions; n++) {
AudioChannelLabel label = l->mChannelDescriptions[n].mChannelLabel;
int speaker = ca_label_to_mp_speaker_id(label);
@@ -158,10 +159,8 @@ static bool ca_layout_to_mp_chmap(struct ao *ao, AudioChannelLayout *layout,
MP_VERBOSE(ao, "channel label=%u unusable to build channel "
"bitmap, skipping layout\n", (unsigned) label);
goto coreaudio_error;
- } else {
- chmap->speaker[n] = speaker;
- chmap->num = n + 1;
}
+ chmap->speaker[n] = speaker;
}
talloc_free(talloc_ctx);