Skip to content

Commit

Permalink
pulse: fix possible overflow for buffer_time option
Browse files Browse the repository at this point in the history
The int cast is wrong and unnecessary as internal->buffer_time is a
pa_usec_t (which is uint64_t). It does not even make sense to cast
it to a uint as it being multiplied by the sample rate (and then
divided by 1000000 before it get fitted into battr.tlength, which
is a uint32_t).

Also ditch the "+7" trick for format->bits as the function would
have returned already if it isn't 8/16(/24).
  • Loading branch information
tomty89 committed Aug 1, 2018
1 parent d522165 commit f4c40b8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/plugins/pulse/ao_pulse.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ int ao_plugin_open(ao_device *device, ao_sample_format *format) {
/* buffering attributes */
battr.prebuf = battr.minreq = battr.fragsize = -1;

battr.tlength = (int)(internal->buffer_time * format->rate) / 1000000 *
((format->bits+7)/8) * device->output_channels;
battr.tlength = internal->buffer_time * format->rate / 1000000 *
(format->bits / 8) * device->output_channels;
battr.minreq = battr.tlength/4;
battr.maxlength = battr.tlength+battr.minreq;

Expand Down

0 comments on commit f4c40b8

Please sign in to comment.