[PATCH] D148959: [Demangle] replace std::string_view::substr which may throw

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 21 15:57:32 PDT 2023


nickdesaulniers updated this revision to Diff 515946.
nickdesaulniers edited the summary of this revision.
nickdesaulniers added a comment.

- update which copy is the upstream in commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148959

Files:
  llvm/include/llvm/Demangle/ItaniumDemangle.h


Index: llvm/include/llvm/Demangle/ItaniumDemangle.h
===================================================================
--- llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -1842,7 +1842,7 @@
       OB += "0";
     } else if (Offset[0] == 'n') {
       OB += "-";
-      OB += Offset.substr(1);
+      OB += std::string_view(Offset.data() + 1, Offset.size() - 1);
     } else {
       OB += Offset;
     }
@@ -2270,7 +2270,7 @@
     OB.printClose();
 
     if (Integer[0] == 'n')
-      OB << '-' << Integer.substr(1);
+      OB << '-' << std::string_view(Integer.data() + 1, Integer.size() - 1);
     else
       OB << Integer;
   }
@@ -2294,7 +2294,7 @@
     }
 
     if (Value[0] == 'n')
-      OB << '-' << Value.substr(1);
+      OB << '-' << std::string_view(Value.data() + 1, Value.size() - 1);
     else
       OB += Value;
 
@@ -3713,7 +3713,8 @@
 
     // extension            ::= U <objc-name> <objc-type>  # objc-type<identifier>
     if (llvm::itanium_demangle::starts_with(Qual, "objcproto")) {
-      std::string_view ProtoSourceName = Qual.substr(std::strlen("objcproto"));
+      constexpr size_t Len = sizeof("objcproto") - 1;
+      std::string_view ProtoSourceName(Qual.data() + Len, Qual.size() - Len);
       std::string_view Proto;
       {
         ScopedOverride<const char *> SaveFirst(First, &*ProtoSourceName.begin()),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148959.515946.patch
Type: text/x-patch
Size: 1395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230421/cd72b175/attachment.bin>


More information about the llvm-commits mailing list