[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-bugs] #24794 [Core Tor/Tor]: smartlist.rs: do not use i8 interchangeably with libc::c_char
#24794: smartlist.rs: do not use i8 interchangeably with libc::c_char
------------------------------+--------------------------------
Reporter: nickm | Owner: nickm
Type: defect | Status: assigned
Priority: Medium | Milestone: Tor: 0.3.3.x-final
Component: Core Tor/Tor | Version:
Severity: Normal | Keywords: rust
Actual Points: | Parent ID:
Points: | Reviewer:
Sponsor: |
------------------------------+--------------------------------
I tried to look at why our arm rust builds are failing, and found these
warnings:
{{{
20:53:59 --> /srv/jenkins-workspace/workspace/tor-ci-linux-master-rust-
arm/ARCHITECTURE/armhf/SUITE/sid/tor/src/rust/smartlist/smartlist.rs:37:44
20:53:59 |
20:53:59 37 | unsafe { slice::from_raw_parts(self.list,
self.num_used as usize) };
20:53:59 | ^^^^^^^^^
expected i8, found u8
20:53:59 |
20:53:59 = note: expected type `*const *const i8`
20:53:59 found type `*const *const u8`
20:53:59
20:53:59 error[E0308]: mismatched types
20:53:59 --> /srv/jenkins-workspace/workspace/tor-ci-linux-master-rust-
arm/ARCHITECTURE/armhf/SUITE/sid/tor/src/rust/smartlist/smartlist.rs:46:52
20:53:59 |
20:53:59 46 | let c_string = unsafe { CStr::from_ptr(*elem) };
20:53:59 | ^^^^^
expected u8, found i8
20:53:59 |
20:53:59 = note: expected type `*const u8`
20:53:59 found type `*const i8`
20:53:59
}}}
They happen because we're declaring Stringlist::list as `c_char`, but
we're declaring elems as `i8`. That's fine on platforms where C's `char`
is signed, but on other platforms, `char` is unsigned, and libc::c_char is
`u8`.
I believe we can fix this by changing `i8` to `c_char` on this line:
{{{
let elems: &[*const i8] =
unsafe { slice::from_raw_parts(self.list, self.num_used as
usize) };
}}}
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/24794>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
_______________________________________________
tor-bugs mailing list
tor-bugs@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-bugs