diff options
author | Szymon Janc <szymon.janc@tieto.com> | 2015-03-31 17:01:24 +0200 |
---|---|---|
committer | Szymon Janc <szymon.janc@tieto.com> | 2015-03-31 20:06:03 +0200 |
commit | 20bcb9bc1a4b9307d21164a5d910c55cd5c48bbf (patch) | |
tree | d26e318ccb02e7a0275a5ff50ac7949c6011f0ae /android/hal-sco.c | |
parent | 5e36d4e8ed8821fe4cb8ee6849ce991aac49a23e (diff) | |
download | bluez-20bcb9bc1a4b9307d21164a5d910c55cd5c48bbf.tar.gz |
android/hal-sco: Fix divide by zero
audio_stream_in_frame_size or audio_stream_frame_size can return 0 so
this needs to be checked before divide.
Diffstat (limited to 'android/hal-sco.c')
-rw-r--r-- | android/hal-sco.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/android/hal-sco.c b/android/hal-sco.c index 380b2a89d..2c95866e7 100644 --- a/android/hal-sco.c +++ b/android/hal-sco.c @@ -1054,17 +1054,23 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer, size_t bytes) { struct sco_stream_in *in = (struct sco_stream_in *) stream; -#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0) - size_t frame_size = audio_stream_in_frame_size(&in->stream); -#else - size_t frame_size = audio_stream_frame_size(&stream->common); -#endif - size_t frame_num = bytes / frame_size; - size_t input_frame_num = frame_num; + size_t frame_size, frame_num, input_frame_num; void *read_buf = buffer; size_t total = bytes; int ret; +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0) + frame_size = audio_stream_in_frame_size(&in->stream); +#else + frame_size = audio_stream_frame_size(&stream->common); +#endif + + if (!frame_size) + return -1; + + frame_num = bytes / frame_size; + input_frame_num = frame_num; + DBG("Read from fd %d bytes %zu", sco_fd, bytes); if (ipc_get_sco_fd(&in->bd_addr) != SCO_STATUS_SUCCESS) |