Commit ee4af482 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Avoid out-of-bounds access via std::vector::operator[].

This triggered C++ STL debug checks, and actually is undefined behaviour,
although it didn't really cause any problems so far.
Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent ab9c7131
...@@ -110,7 +110,7 @@ SFOutputStream::write_frames (const vector<float>& samples) ...@@ -110,7 +110,7 @@ SFOutputStream::write_frames (const vector<float>& samples)
} }
sf_count_t frames = samples.size() / m_n_channels; sf_count_t frames = samples.size() / m_n_channels;
sf_count_t count = sf_writef_int (m_sndfile, &isamples[0], frames); sf_count_t count = sf_writef_int (m_sndfile, isamples.data(), frames);
if (sf_error (m_sndfile)) if (sf_error (m_sndfile))
return Error (sf_strerror (m_sndfile)); return Error (sf_strerror (m_sndfile));
......
...@@ -136,7 +136,7 @@ StdoutWavOutputStream::write_frames (const vector<float>& samples) ...@@ -136,7 +136,7 @@ StdoutWavOutputStream::write_frames (const vector<float>& samples)
m_raw_converter->to_raw (samples, output_bytes); m_raw_converter->to_raw (samples, output_bytes);
fwrite (&output_bytes[0], 1, output_bytes.size(), stdout); fwrite (output_bytes.data(), 1, output_bytes.size(), stdout);
if (ferror (stdout)) if (ferror (stdout))
return Error ("write sample data failed"); return Error ("write sample data failed");
......
...@@ -214,9 +214,9 @@ public: ...@@ -214,9 +214,9 @@ public:
{ {
const size_t synth_frame_sz = Params::frame_size * n_channels; const size_t synth_frame_sz = Params::frame_size * n_channels;
/* move frame 1 and frame 2 to frame 0 and frame 1 */ /* move frame 1 and frame 2 to frame 0 and frame 1 */
std::copy (&synth_samples[synth_frame_sz], &synth_samples[synth_frame_sz * 3], &synth_samples[0]); std::copy (synth_samples.begin() + synth_frame_sz, synth_samples.end(), synth_samples.begin());
/* zero out frame 2 */ /* zero out frame 2 */
std::fill (&synth_samples[synth_frame_sz * 2], &synth_samples[synth_frame_sz * 3], 0); std::fill (synth_samples.begin() + synth_frame_sz * 2, synth_samples.end(), 0);
for (int ch = 0; ch < n_channels; ch++) for (int ch = 0; ch < n_channels; ch++)
{ {
/* mix watermark signal to output frame */ /* mix watermark signal to output frame */
...@@ -418,7 +418,7 @@ public: ...@@ -418,7 +418,7 @@ public:
} }
uint start = 0; uint start = 0;
do while (start != frames.size() / n_channels)
{ {
const int out_count = Params::frame_size; const int out_count = Params::frame_size;
float out[out_count * n_channels]; float out[out_count * n_channels];
...@@ -435,7 +435,6 @@ public: ...@@ -435,7 +435,6 @@ public:
start = frames.size() / n_channels - m_resampler.inp_count; start = frames.size() / n_channels - m_resampler.inp_count;
} }
while (start != frames.size() / n_channels);
} }
vector<float> vector<float>
read_frames (size_t frames) read_frames (size_t frames)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment