output/osx: don't use variable-length arrays

This commit is contained in:
Max Kellermann 2019-06-08 11:51:15 +02:00
parent 931c3a1de0
commit 3055c1266d
1 changed files with 10 additions and 2 deletions

View File

@ -390,7 +390,11 @@ osx_output_set_device_format(AudioDeviceID dev_id, const AudioStreamBasicDescrip
} }
const size_t n_streams = property_size / sizeof(AudioStreamID); const size_t n_streams = property_size / sizeof(AudioStreamID);
AudioStreamID streams[n_streams]; static constexpr size_t MAX_STREAMS = 64;
if (n_streams > MAX_STREAMS)
throw std::runtime_error("Too many streams");
AudioStreamID streams[MAX_STREAMS];
err = AudioObjectGetPropertyData(dev_id, &aopa, 0, NULL, &property_size, streams); err = AudioObjectGetPropertyData(dev_id, &aopa, 0, NULL, &property_size, streams);
if (err != noErr) { if (err != noErr) {
throw FormatRuntimeError("Cannot get streams: %d\n", err); throw FormatRuntimeError("Cannot get streams: %d\n", err);
@ -424,7 +428,11 @@ osx_output_set_device_format(AudioDeviceID dev_id, const AudioStreamBasicDescrip
throw FormatRuntimeError("Unable to get format size s for stream %d. Error = %s", streams[i], err); throw FormatRuntimeError("Unable to get format size s for stream %d. Error = %s", streams[i], err);
const size_t format_count = property_size / sizeof(AudioStreamRangedDescription); const size_t format_count = property_size / sizeof(AudioStreamRangedDescription);
AudioStreamRangedDescription format_list[format_count]; static constexpr size_t MAX_FORMATS = 256;
if (format_count > MAX_FORMATS)
throw std::runtime_error("Too many formats");
AudioStreamRangedDescription format_list[MAX_FORMATS];
err = AudioObjectGetPropertyData(stream, &aopa, 0, NULL, &property_size, format_list); err = AudioObjectGetPropertyData(stream, &aopa, 0, NULL, &property_size, format_list);
if (err != noErr) if (err != noErr)
throw FormatRuntimeError("Unable to get available formats for stream %d. Error = %s", streams[i], err); throw FormatRuntimeError("Unable to get available formats for stream %d. Error = %s", streams[i], err);