MidiBuffer::Iterator::getNextEvent memory error detected by valgrind

Hi jules.


When running my application through valgrind, I spotted this:

==31002== Thread 6:
==31002== Invalid read of size 1
==31002==    at 0x4C2D1AD: memcpy@@GLIBC_2.14 (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==31002==    by 0x64F4EC: juce::MidiMessage::MidiMessage(void const*, int, double) (juce_MidiMessage.cpp:117)
==31002==    by 0x64D7C1: juce::MidiBuffer::Iterator::getNextEvent(juce::MidiMessage&, int&) (juce_MidiBuffer.cpp:225)

A little after that I got some more errors, which I assume first came from this (which I later confirmed).


Looking at that line (juce_MidiBuffer.cpp:225), I tested a few things, and made a small fix:

-    data += numBytes;
+    data += sizeof (int32) + sizeof (uint16) + numBytes;


This is quite nasty... not sure how the direct midi data has the correct "+=" but the MidiMessage variant did not.

And yes, this is the latest git, from today.

With that fix I no longer get valgrind errors, which tells me the fix is correct.

Ah, thanks! I actually only just checked that code in yesterday and hadn't fully tested it yet - should be ok now!

ah that explains it, thanks!