Skip to content
Snippets Groups Projects
Closed (moved) smartlist.rs: do not use i8 interchangeably with libc::c_char
  • View options
  • smartlist.rs: do not use i8 interchangeably with libc::c_char

  • View options
  • Closed (moved) Issue created by Nick Mathewson

    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) };

    Linked items ... 0

  • Activity

    • All activity
    • Comments only
    • History only
    • Newest first
    • Oldest first
    Loading Loading Loading Loading Loading Loading Loading Loading Loading Loading