#24794 closed defect (fixed)

smartlist.rs: do not use i8 interchangeably with libc::c_char

Reported by: nickm Owned by: nickm
Priority: Medium Milestone: Tor: 0.3.3.x-final
Component: Core Tor/Tor Version:
Severity: Normal Keywords: rust
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

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

Child Tickets

Change History (2)

comment:1 Changed 22 months ago by nickm

I have committed 1dab8bae21bc32e5d4e3ff954f4919d6506ad2e1 to fix this. It works fine on x86_64 linux: let's see if the arm builders are happy now.

comment:2 Changed 22 months ago by nickm

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.