diff options
-rw-r--r-- | src/murmur/AudioReceiverBuffer.h | 8 | ||||
-rw-r--r-- | src/tests/TestAudioReceiverBuffer/TestAudioReceiverBuffer.cpp | 13 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/murmur/AudioReceiverBuffer.h b/src/murmur/AudioReceiverBuffer.h index 9d2aeefc8..b5d6d9822 100644 --- a/src/murmur/AudioReceiverBuffer.h +++ b/src/murmur/AudioReceiverBuffer.h @@ -68,6 +68,14 @@ public: ReceiverRange< Iterator > range; range.begin = begin; + if (begin == end) { + // In this case, it is invalid to dereference begin (as is done further down) and thus we have to + // return early instead. + range.end = end; + + return range; + } + // Find a range, such that all receivers in [begin, end) are compatible in the sense that they will all receive // the exact same audio packet (thus: no re-encoding required between sending the packet to them). range.end = std::lower_bound(begin, end, *begin, [](const AudioReceiver &lhs, const AudioReceiver &rhs) { diff --git a/src/tests/TestAudioReceiverBuffer/TestAudioReceiverBuffer.cpp b/src/tests/TestAudioReceiverBuffer/TestAudioReceiverBuffer.cpp index 3d37c3099..c04188a34 100644 --- a/src/tests/TestAudioReceiverBuffer/TestAudioReceiverBuffer.cpp +++ b/src/tests/TestAudioReceiverBuffer/TestAudioReceiverBuffer.cpp @@ -270,6 +270,19 @@ private slots: qDebug() << "Sample receiver list required" << requiredReencodings << "encoding steps"; } + + void test_emptyRange() { + AudioReceiverBuffer buffer; + + std::vector< AudioReceiver > receivers = buffer.getReceivers(true); + + QVERIFY(receivers.empty()); + + ReceiverRange< std::vector< AudioReceiver >::iterator > range = + AudioReceiverBuffer::getReceiverRange(receivers.begin(), receivers.end()); + + QCOMPARE(range.begin, range.end); + } }; QTEST_MAIN(TestAudioReceiverBuffer) |