about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm/metadata.rs
diff options
context:
space:
mode:
authorValentin Tolmer <valentin.tolmer@gmail.com>2019-03-27 15:57:14 +0100
committerRalf Jung <post@ralfj.de>2019-07-07 09:31:41 +0200
commitf5b30211c8fe3acb93be9a748004ee835adaa6e4 (patch)
treecd04468df2c42ff4cfe9763804a9289ec2eaf6af /src/librustc_codegen_llvm/metadata.rs
parent4393768faa104b9879c601feee71eb0207dc4fe1 (diff)
downloadrust-f5b30211c8fe3acb93be9a748004ee835adaa6e4.tar.gz
rust-f5b30211c8fe3acb93be9a748004ee835adaa6e4.zip
Handle null from LLVMRustGetSectionName
Diffstat (limited to 'src/librustc_codegen_llvm/metadata.rs')
-rw-r--r--src/librustc_codegen_llvm/metadata.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/librustc_codegen_llvm/metadata.rs b/src/librustc_codegen_llvm/metadata.rs
index 7cf497cb5d0..9bddd29d2e8 100644
--- a/src/librustc_codegen_llvm/metadata.rs
+++ b/src/librustc_codegen_llvm/metadata.rs
@@ -8,7 +8,6 @@ use rustc_data_structures::owning_ref::OwningRef;
 use rustc_codegen_ssa::METADATA_FILENAME;
 
 use std::path::Path;
-use std::ptr;
 use std::slice;
 use rustc_fs_util::path_to_c_string;
 
@@ -67,10 +66,14 @@ fn search_meta_section<'a>(of: &'a ObjectFile,
     unsafe {
         let si = mk_section_iter(of.llof);
         while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
-            let mut name_buf = ptr::null();
+            let mut name_buf = None;
             let name_len = llvm::LLVMRustGetSectionName(si.llsi, &mut name_buf);
-            let name = slice::from_raw_parts(name_buf as *const u8, name_len as usize).to_vec();
-            let name = String::from_utf8(name).unwrap();
+            let name = name_buf.map_or(
+                "".to_string(),
+                |buf| String::from_utf8(
+                    slice::from_raw_parts(buf.as_ptr() as *const u8,
+                                          name_len as usize)
+                    .to_vec()).unwrap());
             debug!("get_metadata_section: name {}", name);
             if read_metadata_section_name(target) == name {
                 let cbuf = llvm::LLVMGetSectionContents(si.llsi);