[Problem]
SVACE Warning Message:
The value of an arithmetic expression 'bytes_per_frame_ * sample_rate_'
is a subject to overflow because its operands are not cast to a larger
data type before performing arithmetic
[Solution]
Due to restriction on maximal values of:
- `bytes_per_frame_` - it is maximum number of bytes per audio frame
and can be at most 8 * 4 = 32, as there will at most 8 audio channels
and each channel date will be at most 4 bytes per (in case of using
32bit float value).
- `sample_rate_` - it is maximum audio sampling rate most probably 48kHz
with maximal values just below 200kHz.
So value of mentioned expression won't be larger than 6'400'000
(32 * 200'000), which fits 32bit unsigned integer.
To explicitly express this separate variable holding value of this
expression is added.
Bug:
DF241205-01887
Bug: https://jira-eu.sec.samsung.net/browse/VDWASM-2009
Signed-off-by: Adam Bujalski <a.bujalski@samsung.com>
Change-Id: I474dd075f9296027b24b08a4199fe25b5403cda2
// Write at most kDefaultChunkDuration of audio data to ensure
// that device will be filled constantly.
- const int max_write_size = (bytes_per_frame_ * sample_rate_ *
- kDefaultChunkDuration.InMilliseconds()) /
- base::Time::kMillisecondsPerSecond;
+ const uint32_t bytes_per_second = bytes_per_frame_ * sample_rate_;
+ const int max_write_size =
+ (bytes_per_second * kDefaultChunkDuration.InMilliseconds()) /
+ base::Time::kMillisecondsPerSecond;
const int write_size = std::min(buffer_size, max_write_size);
size_t bytes_written = device_->Write(buffer_data, write_size);
if (bytes_written > 0) {