From 1cc371cae94efe7f2ff3cb84df59496f73db814c Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 5 Sep 2017 16:39:51 +0100 Subject: [PATCH] Fix for an AudioBuffer move operator bug --- .../buffers/juce_AudioSampleBuffer.h | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h index ed945e0896..6ef06a177f 100644 --- a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h +++ b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h @@ -184,11 +184,19 @@ public: : numChannels (other.numChannels), size (other.size), allocatedBytes (other.allocatedBytes), - channels (numChannels < (int) numElementsInArray (preallocatedChannelSpace) ? preallocatedChannelSpace : other.channels), allocatedData (static_cast&&> (other.allocatedData)), isClear (other.isClear) { - memcpy (preallocatedChannelSpace, other.preallocatedChannelSpace, sizeof (preallocatedChannelSpace)); + if (numChannels < (int) numElementsInArray (preallocatedChannelSpace)) + { + channels = preallocatedChannelSpace; + memcpy (preallocatedChannelSpace, other.channels, sizeof (preallocatedChannelSpace)); + } + else + { + channels = other.channels; + } + other.numChannels = 0; other.size = 0; other.allocatedBytes = 0; @@ -200,10 +208,19 @@ public: numChannels = other.numChannels; size = other.size; allocatedBytes = other.allocatedBytes; - channels = numChannels < (int) numElementsInArray (preallocatedChannelSpace) ? preallocatedChannelSpace : other.channels; allocatedData = static_cast&&> (other.allocatedData); isClear = other.isClear; - memcpy (preallocatedChannelSpace, other.preallocatedChannelSpace, sizeof (preallocatedChannelSpace)); + + if (numChannels < (int) numElementsInArray (preallocatedChannelSpace)) + { + channels = preallocatedChannelSpace; + memcpy (preallocatedChannelSpace, other.channels, sizeof (preallocatedChannelSpace)); + } + else + { + channels = other.channels; + } + other.numChannels = 0; other.size = 0; other.allocatedBytes = 0;