Skip to content

Commit d77e000

Browse files
committed
Clarify hazards in 'as *const _ casts of *const u8 to *const libc::c_char`.
1 parent 398b5d7 commit d77e000

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/util_libc.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ impl Weak {
117117
// the use of non-Relaxed operations is probably unnecessary.
118118
match self.addr.load(Ordering::Relaxed) {
119119
Self::UNINIT => {
120-
let symbol = self.name.as_ptr() as *const _;
120+
// XXX/FIXME: Unchecked UTF-8-to-c_char cast.
121+
let symbol = self.name.as_ptr().cast::<libc::c_char>();
121122
let addr = unsafe { libc::dlsym(libc::RTLD_DEFAULT, symbol) };
122123
// Synchronizes with the Acquire fence below
123124
self.addr.store(addr, Ordering::Release);
@@ -136,7 +137,11 @@ impl Weak {
136137
pub unsafe fn open_readonly(path: &str) -> Result<libc::c_int, Error> {
137138
debug_assert_eq!(path.as_bytes().last(), Some(&0));
138139
loop {
139-
let fd = libc::open(path.as_ptr() as *const _, libc::O_RDONLY | libc::O_CLOEXEC);
140+
// XXX/FIXME: Unchecked UTF-8-to-c_char cast.
141+
let fd = libc::open(
142+
path.as_ptr().cast::<libc::c_char>(),
143+
libc::O_RDONLY | libc::O_CLOEXEC,
144+
);
140145
if fd >= 0 {
141146
return Ok(fd);
142147
}

0 commit comments

Comments
 (0)