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

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 12 14:44:53 PDT 2022


int3 added inline comments.


================
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);
----------------
dereferencing end iterators from the STL is undefined, but fortunately a StringRef isn't part of the STL...


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