diff options
| author | Michael Krasnitski <michael.krasnitski@gmail.com> | 2023-01-06 02:04:49 -0500 |
|---|---|---|
| committer | Kyle Martin <krm504@nyu.edu> | 2023-01-10 00:11:27 -0500 |
| commit | 5b51a4ff188c426d8f90ac71ee6dde0fa3b5a495 (patch) | |
| tree | e7a8b87d95061e549ee48063999b838c56dba3a7 /rust/src/section.rs | |
| parent | 7eb2b8fc3bd39324a74e02652c8f678073947812 (diff) | |
Clean up various builders
Diffstat (limited to 'rust/src/section.rs')
| -rw-r--r-- | rust/src/section.rs | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/rust/src/section.rs b/rust/src/section.rs index 49642b4d..971204ba 100644 --- a/rust/src/section.rs +++ b/rust/src/section.rs @@ -70,13 +70,12 @@ impl Section { Self { handle: raw } } - #[allow(clippy::new_ret_no_self)] /// You need to create a section builder, customize that section, then add it to a binary view: /// /// ``` /// bv.add_section(Section::new().align(4).entry_size(4)) /// ``` - pub fn new<S: BnStrCompatible>(name: S, range: Range<u64>) -> SectionBuilder<S> { + pub fn builder<S: BnStrCompatible>(name: S, range: Range<u64>) -> SectionBuilder<S> { SectionBuilder::new(name, range) } @@ -204,7 +203,7 @@ pub struct SectionBuilder<S: BnStrCompatible> { impl<S: BnStrCompatible> SectionBuilder<S> { pub fn new(name: S, range: Range<u64>) -> Self { - SectionBuilder { + Self { is_auto: false, name, range, @@ -268,19 +267,12 @@ impl<S: BnStrCompatible> SectionBuilder<S> { let len = self.range.end.wrapping_sub(start); unsafe { - use std::ffi::CStr; - - let nul_str = CStr::from_bytes_with_nul_unchecked(b"\x00").as_ptr(); + let nul_str = std::ffi::CStr::from_bytes_with_nul_unchecked(b"\x00").as_ptr(); let name_ptr = name.as_ref().as_ptr() as *mut _; - let ty_ptr = ty - .as_ref() - .map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); - let linked_section_ptr = linked_section - .as_ref() - .map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); - let info_section_ptr = info_section - .as_ref() - .map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); + let ty_ptr = ty.map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); + let linked_section_ptr = + linked_section.map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); + let info_section_ptr = info_section.map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); if self.is_auto { BNAddAutoSection( |
