From 146f486ba337299b88df303a6f1cf99f60df03cc Mon Sep 17 00:00:00 2001 From: Joshua Root Date: Fri, 24 Jun 2022 09:12:55 -0700 Subject: [PATCH] [ObjCopy] Fix type mismatch in writeCodeSignatureData() The result of pointer subtraction is of type ptrdiff_t, which is not necessarily the same underlying type as ssize_t. This can lead to a compilation error since std::min requires both parameters to be the same type. Fixes: https://github.com/llvm/llvm-project/issues/54846 Reviewed By: alexander-shaposhnikov, drodriguez, jhenderson Differential Revision: https://reviews.llvm.org/D128117 --- llvm/lib/ObjCopy/MachO/MachOWriter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llvm/lib/ObjCopy/MachO/MachOWriter.cpp b/llvm/lib/ObjCopy/MachO/MachOWriter.cpp index 9b1fd58..bc63328 100644 --- a/llvm/lib/ObjCopy/MachO/MachOWriter.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOWriter.cpp @@ -520,8 +520,9 @@ void MachOWriter::writeCodeSignatureData() { uint8_t *CurrHashWritePosition = HashWriteStart; while (CurrHashReadPosition < HashReadEnd) { StringRef Block(reinterpret_cast(CurrHashReadPosition), - std::min(HashReadEnd - CurrHashReadPosition, - static_cast(CodeSignature.BlockSize))); + std::min(static_cast(HashReadEnd + - CurrHashReadPosition), + static_cast(CodeSignature.BlockSize))); SHA256 Hasher; Hasher.update(Block); std::array Hash = Hasher.final(); -- 2.7.4