[PATCH] D128295: [lld/mac] Replace while loop with for loop

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 12:45:17 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG3ade3d372408: [lld/mac] Replace while loop with for loop (authored by thakis).
Herald added a project: LLVM.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128295/new/

https://reviews.llvm.org/D128295

Files:
  lld/MachO/SyntheticSections.cpp


Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -1253,14 +1253,11 @@
 void CodeSignatureSection::writeHashes(uint8_t *buf) const {
   // NOTE: Changes to this functionality should be repeated in llvm-objcopy's
   // MachOWriter::writeSignatureData.
-  uint8_t *code = buf;
-  uint8_t *codeEnd = buf + fileOff;
-  uint8_t *hashes = codeEnd + allHeadersSize;
-  while (code < codeEnd) {
-    sha256(code, std::min(static_cast<size_t>(codeEnd - code), blockSize),
-           hashes);
-    code += blockSize;
-    hashes += hashSize;
+  uint8_t *hashes = buf + fileOff + allHeadersSize;
+  for (uint64_t i = 0; i < getBlockCount(); ++i) {
+    sha256(buf + i * blockSize,
+           std::min(static_cast<size_t>(fileOff - i * blockSize), blockSize),
+           hashes + i * hashSize);
   }
 #if defined(__APPLE__)
   // This is macOS-specific work-around and makes no sense for any


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128295.438802.patch
Type: text/x-patch
Size: 1015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220621/9a96604b/attachment.bin>


More information about the llvm-commits mailing list