From 0979097cae276b82ccedd3cf46262232c2d17122 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Tue, 10 Nov 2020 20:41:54 +0900 Subject: [PATCH] Check for MIDI buffer overflow when merging into an empty buffer This can happen if the buffers have different sizes. This fixes crashes that bisected to 7c37a18b7, but it is not the root cause; it just happened to make things worse. --- libs/ardour/midi_buffer.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/ardour/midi_buffer.cc b/libs/ardour/midi_buffer.cc index 6707465c44..d0e9882aeb 100644 --- a/libs/ardour/midi_buffer.cc +++ b/libs/ardour/midi_buffer.cc @@ -442,15 +442,15 @@ MidiBuffer::merge_in_place (const MidiBuffer &other) return true; } + if (size() + other.size() > _capacity) { + return false; + } + if (size() == 0) { copy (other); return true; } - if (size() + other.size() > _capacity) { - return false; - } - const_iterator them = other.begin(); iterator us = begin();