[PATCH] D127902: [Object][COFF] Improve section name parsing

Pengxuan Zheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 16 14:55:33 PDT 2022


pzheng updated this revision to Diff 437719.
pzheng added a comment.

Use getAsInteger


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127902

Files:
  llvm/lib/Object/COFFObjectFile.cpp


Index: llvm/lib/Object/COFFObjectFile.cpp
===================================================================
--- llvm/lib/Object/COFFObjectFile.cpp
+++ llvm/lib/Object/COFFObjectFile.cpp
@@ -1146,13 +1146,7 @@
 
 Expected<StringRef>
 COFFObjectFile::getSectionName(const coff_section *Sec) const {
-  StringRef Name;
-  if (Sec->Name[COFF::NameSize - 1] == 0)
-    // Null terminated, let ::strlen figure out the length.
-    Name = Sec->Name;
-  else
-    // Not null terminated, use all 8 bytes.
-    Name = StringRef(Sec->Name, COFF::NameSize);
+  StringRef Name = StringRef(Sec->Name, COFF::NameSize).split('\0').first;
 
   // Check for string table entry. First byte is '/'.
   if (Name.startswith("/")) {
@@ -1162,7 +1156,7 @@
         return createStringError(object_error::parse_failed,
                                  "invalid section name");
     } else {
-      if (Name.substr(1).consumeInteger(10, Offset))
+      if (Name.substr(1).getAsInteger(10, Offset))
         return createStringError(object_error::parse_failed,
                                  "invalid section name");
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127902.437719.patch
Type: text/x-patch
Size: 1104 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220616/5262525c/attachment.bin>


More information about the llvm-commits mailing list