Skip to content

Commit a3b8324

Browse files
committed
Make symbol and section names optional, for when llvm returns a nullptr.
1 parent 41b9624 commit a3b8324

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/object_file.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,14 @@ impl Section {
108108
}
109109
}
110110

111-
pub fn get_name(&self) -> &CStr {
112-
unsafe {
113-
CStr::from_ptr(LLVMGetSectionName(self.section))
111+
pub fn get_name(&self) -> Option<&CStr> {
112+
let name = unsafe {
113+
LLVMGetSectionName(self.section)
114+
}
115+
if !name.is_null() {
116+
CStr::from_ptr(name)
117+
} else {
118+
None
114119
}
115120
}
116121

@@ -302,9 +307,14 @@ impl Symbol {
302307
}
303308
}
304309

305-
pub fn get_name(&self) -> &CStr {
306-
unsafe {
307-
CStr::from_ptr(LLVMGetSymbolName(self.symbol))
310+
pub fn get_name(&self) -> Option<&CStr> {
311+
let name = unsafe {
312+
LLVMGetSymbolName(self.symbol)
313+
}
314+
if !name.is_null() {
315+
CStr::from_ptr(name)
316+
} else {
317+
None
308318
}
309319
}
310320

0 commit comments

Comments
 (0)