diff 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
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;