From 63173d11ecb50236e86578574584bd9a86e27387 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Wed, 21 Dec 2022 16:02:38 -0800 Subject: [PATCH] [lld-macho] Fix assert when splitting section Fixes https://github.com/llvm/llvm-project/issues/59649 Differential Revision: https://reviews.llvm.org/D140518 --- lld/MachO/InputFiles.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp index 174ad95..49629ab 100644 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -329,14 +329,14 @@ void ObjFile::parseSections(ArrayRef sectionHeaders) { : buf + sec.offset, static_cast(sec.size)}; - auto splitRecords = [&](int recordSize) -> void { + auto splitRecords = [&](size_t recordSize) -> void { if (data.empty()) return; Subsections &subsections = section.subsections; subsections.reserve(data.size() / recordSize); for (uint64_t off = 0; off < data.size(); off += recordSize) { auto *isec = make( - section, data.slice(off, recordSize), align); + section, data.slice(off, std::min(data.size(), recordSize)), align); subsections.push_back({off, isec}); } section.doneSplitting = true; -- 2.7.4