comparison data/fileio/CodedAudioFileReader.cpp @ 1052:e603b44510c3 cxx11

Fix buffer overwrite in normalised case
author Chris Cannam
date Wed, 11 Mar 2015 11:03:22 +0000
parents 843f67be0ed9
children 4d9816ba0ebe 1517d4c60e88
comparison
equal deleted inserted replaced
1051:cafd65fc411b 1052:e603b44510c3
437 437
438 sv_frame_t idx = start * m_channelCount; 438 sv_frame_t idx = start * m_channelCount;
439 sv_frame_t i = 0; 439 sv_frame_t i = 0;
440 sv_frame_t n = count * m_channelCount; 440 sv_frame_t n = count * m_channelCount;
441 441
442 frames.resize(n);
443
442 m_dataLock.lockForRead(); 444 m_dataLock.lockForRead();
443 while (i < n && in_range_for(m_data, idx)) { 445 while (i < n && in_range_for(m_data, idx)) {
444 frames.push_back(m_data[idx++]); 446 frames[i++] = m_data[idx++];
445 ++i;
446 } 447 }
447 m_dataLock.unlock(); 448 m_dataLock.unlock();
449
450 frames.resize(i);
448 } 451 }
449 } 452 }
450 453
451 if (m_normalised) { 454 if (m_normalised) {
452 for (sv_frame_t i = 0; i < (sv_frame_t)(count * m_channelCount); ++i) { 455 for (auto &f: frames) f *= m_gain;
453 frames[i] *= m_gain;
454 }
455 } 456 }
456 457
457 return frames; 458 return frames;
458 } 459 }
459 460