Skip to content

Commit 2e0c460

Browse files
committed
[Object][COFF] Improve section name parsing
Inspired by discussions on D127369, we probably can further improve LLVM's COFF section name parsing. Hopefully, this makes the logic simpler and handles some edge cases more elegantly. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D127902
1 parent 0e18246 commit 2e0c460

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

llvm/lib/Object/COFFObjectFile.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,13 +1146,7 @@ uint32_t COFFObjectFile::getSymbolIndex(COFFSymbolRef Symbol) const {
11461146

11471147
Expected<StringRef>
11481148
COFFObjectFile::getSectionName(const coff_section *Sec) const {
1149-
StringRef Name;
1150-
if (Sec->Name[COFF::NameSize - 1] == 0)
1151-
// Null terminated, let ::strlen figure out the length.
1152-
Name = Sec->Name;
1153-
else
1154-
// Not null terminated, use all 8 bytes.
1155-
Name = StringRef(Sec->Name, COFF::NameSize);
1149+
StringRef Name = StringRef(Sec->Name, COFF::NameSize).split('\0').first;
11561150

11571151
// Check for string table entry. First byte is '/'.
11581152
if (Name.startswith("/")) {
@@ -1162,7 +1156,7 @@ COFFObjectFile::getSectionName(const coff_section *Sec) const {
11621156
return createStringError(object_error::parse_failed,
11631157
"invalid section name");
11641158
} else {
1165-
if (Name.substr(1).consumeInteger(10, Offset))
1159+
if (Name.substr(1).getAsInteger(10, Offset))
11661160
return createStringError(object_error::parse_failed,
11671161
"invalid section name");
11681162
}

0 commit comments

Comments
 (0)