diff --git a/cpp/mcap/include/mcap/internal.hpp b/cpp/mcap/include/mcap/internal.hpp index 4faedd0b27..69b1dd9d43 100644 --- a/cpp/mcap/include/mcap/internal.hpp +++ b/cpp/mcap/include/mcap/internal.hpp @@ -138,7 +138,11 @@ inline Status ParseByteArray(const std::byte* data, uint64_t maxSize, ByteArray* return Status(StatusCode::InvalidRecord, msg); } output->resize(size); - std::memcpy(output->data(), data + 4, size); + // output->data() may return nullptr if 'output' is empty, but memcpy() does not accept nullptr. + // 'output' will be empty only if the 'size' is equal to 0. + if (size > 0) { + std::memcpy(output->data(), data + 4, size); + } return StatusCode::Success; }