[PATCH] D133728: [lld-macho][nfci] Don't include null terminator in StringRefs

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 12 18:00:02 PDT 2022


thakis added inline comments.


================
Comment at: lld/MachO/InputSection.cpp:244
     if (end == StringRef::npos)
       fatal(getLocation(off) + ": string is not null terminated");
+    uint32_t hash = deduplicateLiterals ? xxHash64(s.take_front(end)) : 0;
----------------
There's a bunch of places that assume that the trailing \0 byte is still there, but that's generally not the case for StringRefs. Maybe we should use ArrayRefs in the places you touched?


================
Comment at: lld/MachO/MapFile.cpp:91
       StringRef str = isec->getStringRef(&piece - &(*isec->pieces.begin()));
-      assert(str.back() == '\000');
-      (os << "literal string: ")
-          // Remove null sequence at the end
-          .write_escaped(str.substr(0, str.size() - 1));
+      assert(*str.end() == '\000');
+      (os << "literal string: ").write_escaped(str);
----------------
int3 wrote:
> dereferencing end iterators from the STL is undefined, but fortunately a StringRef isn't part of the STL...
Looks very fishy though. See above :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133728



More information about the llvm-commits mailing list