Commit cf1842b1 authored by Thomas Eschenbacher's avatar Thomas Eschenbacher
Browse files

bugfix: new data was not initialized in SampleArray::resize()

parent 0010ad23
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* bugfix: cleanup code in destructor of PluginManager caused crash when * bugfix: cleanup code in destructor of PluginManager caused crash when
closing the window due to broken iterator closing the window due to broken iterator
* bugfix: Qt playback plugin crashed when stopping pre-listen * bugfix: Qt playback plugin crashed when stopping pre-listen
* bugfix: new data was not initialized in SampleArray::resize()
20.03.70 [2020-02-16] 20.03.70 [2020-02-16]
......
...@@ -142,8 +142,14 @@ void Kwave::SampleArray::SampleStorage::resize(unsigned int size) ...@@ -142,8 +142,14 @@ void Kwave::SampleArray::SampleStorage::resize(unsigned int size)
::realloc(m_data, size * sizeof(sample_t))); ::realloc(m_data, size * sizeof(sample_t)));
if (new_data) { if (new_data) {
// successful // successful
// NOTE: if we grew, the additional memory is *not* initialized!
m_data = new_data; m_data = new_data;
if (size > m_size) {
// initialize the new data
unsigned int count = size - m_size;
sample_t *p = m_data + m_size;
while (count--)
*(p++) = 0;
}
m_size = size; m_size = size;
} else { } else {
qWarning("Kwave::SampleArray::SampleStorage::resize(%u): OOM! " qWarning("Kwave::SampleArray::SampleStorage::resize(%u): OOM! "
......
...@@ -66,7 +66,7 @@ Kwave::Track::Track(sample_index_t length, QUuid *uuid) ...@@ -66,7 +66,7 @@ Kwave::Track::Track(sample_index_t length, QUuid *uuid)
:m_lock(QMutex::Recursive), m_lock_usage(), m_stripes(), m_selected(true), :m_lock(QMutex::Recursive), m_lock_usage(), m_stripes(), m_selected(true),
m_uuid((uuid) ? *uuid : QUuid::createUuid()) m_uuid((uuid) ? *uuid : QUuid::createUuid())
{ {
if (length < STRIPE_LENGTH_MAXIMUM) { if (length <= STRIPE_LENGTH_MAXIMUM) {
if (length) appendStripe(length); if (length) appendStripe(length);
} else { } else {
Stripe s(length - STRIPE_LENGTH_OPTIMAL); Stripe s(length - STRIPE_LENGTH_OPTIMAL);
......
...@@ -501,7 +501,7 @@ bool Kwave::WavEncoder::encode(QWidget *widget, Kwave::MultiTrackReader &src, ...@@ -501,7 +501,7 @@ bool Kwave::WavEncoder::encode(QWidget *widget, Kwave::MultiTrackReader &src,
for (unsigned int track = 0; track < tracks; track++) { for (unsigned int track = 0; track < tracks; track++) {
Kwave::SampleReader *stream = src[track]; Kwave::SampleReader *stream = src[track];
sample_t sample = 0; sample_t sample = 0;
if (!stream->eof()) (*stream) >> sample; if (stream && !stream->eof()) (*stream) >> sample;
// the following cast is only necessary if // the following cast is only necessary if
// sample_t is not equal to sample_storage_t // sample_t is not equal to sample_storage_t
......
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