changeset 1052:e603b44510c3 cxx11

Fix buffer overwrite in normalised case
author Chris Cannam
date Wed, 11 Mar 2015 11:03:22 +0000
parents cafd65fc411b
children 48e4ffa9fb48
files data/fileio/CodedAudioFileReader.cpp
diffstat 1 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CodedAudioFileReader.cpp	Wed Mar 11 09:29:44 2015 +0000
+++ b/data/fileio/CodedAudioFileReader.cpp	Wed Mar 11 11:03:22 2015 +0000
@@ -439,19 +439,20 @@
         sv_frame_t i = 0;
         sv_frame_t n = count * m_channelCount;
 
+        frames.resize(n);
+
         m_dataLock.lockForRead();
         while (i < n && in_range_for(m_data, idx)) {
-            frames.push_back(m_data[idx++]);
-            ++i;
+            frames[i++] = m_data[idx++];
         }
         m_dataLock.unlock();
+
+        frames.resize(i);
     }
     }
 
     if (m_normalised) {
-        for (sv_frame_t i = 0; i < (sv_frame_t)(count * m_channelCount); ++i) {
-            frames[i] *= m_gain;
-        }
+        for (auto &f: frames) f *= m_gain;
     }
 
     return frames;