diff --git a/firmware/console/binary/FragmentEntry.cpp b/firmware/console/binary/FragmentEntry.cpp index 3953a34bfa..0887adda35 100644 --- a/firmware/console/binary/FragmentEntry.cpp +++ b/firmware/console/binary/FragmentEntry.cpp @@ -24,7 +24,12 @@ void copyRange(uint8_t *destination, FragmentEntry *fragments, size_t dataOffset while (dataLength > 0) { int copyNowSize = minI(dataLength, fragments[fragmentIndex].size - dataOffset); - memcpy(destination + destinationIndex, fragments[fragmentIndex].data + dataOffset, copyNowSize); + const uint8_t *fromBase = fragments[fragmentIndex].data; + if (fromBase == nullptr) { + memset(destination + destinationIndex, 0, copyNowSize); + } else { + memcpy(destination + destinationIndex, fromBase + dataOffset, copyNowSize); + } destinationIndex += copyNowSize; dataOffset = 0; dataLength -= copyNowSize; diff --git a/unit_tests/tests/test_scattered_outputs.cpp b/unit_tests/tests/test_scattered_outputs.cpp index c181a4be95..43d5a75c79 100644 --- a/unit_tests/tests/test_scattered_outputs.cpp +++ b/unit_tests/tests/test_scattered_outputs.cpp @@ -7,6 +7,7 @@ static uint8_t buffer5[] = {11, 12, 13, 14, 15}; static FragmentEntry fragments[] = { FragmentEntry(buffer10, sizeof(buffer10)), FragmentEntry(buffer5, sizeof(buffer5)), + FragmentEntry(nullptr, sizeof(5)), }; TEST(outputs, fragments) { @@ -22,4 +23,10 @@ TEST(outputs, fragments) { copyRange(buffer, fragments, 12, 3); EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected))); } + + { + uint8_t expected[] = {15, 0, 0}; + copyRange(buffer, fragments, 14, 3); + EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected))); + } }