Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91d55db2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add safety comments." into main am: 406d4339 am: 947d407b am:...

Merge "Add safety comments." into main am: 406d4339 am: 947d407b am: 5faeba27 am: ed672df1 am: 17342905

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2672075



Change-Id: Iabf06dbf9f32e0b1e25063d8bbb1646858edd982
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents c1b99121 17342905
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -111,7 +111,9 @@ lazy_static! {
    static ref COOKIES: Mutex<HashMap<i32, fn() -> StatsPullResult>> = Mutex::new(HashMap::new());
}

// Safety: We store our callbacks in the global so they are valid.
/// # Safety
///
/// `data` must be a valid pointer with no aliases.
unsafe extern "C" fn callback_wrapper(
    atom_tag: i32,
    data: *mut AStatsEventList,
@@ -126,7 +128,8 @@ unsafe extern "C" fn callback_wrapper(
                let stats = cb();
                let result = stats
                    .iter()
                    .map(|stat| stat.add_astats_event(&mut *data))
                    // Safety: The caller promises that `data` is valid and unaliased.
                    .map(|stat| stat.add_astats_event(unsafe { &mut *data }))
                    .collect::<Result<Vec<()>, StatsError>>();
                match result {
                    Ok(_) => {
+2 −0
Original line number Diff line number Diff line
@@ -102,6 +102,8 @@ impl TipcChannel {
        let file = File::options().read(true).write(true).open(device)?;

        let srv_name = CString::new(service).expect("Service name contained null bytes");
        // SAFETY: The file descriptor is valid because it came from a `File`, and the name is a
        // valid C string because it came from a `CString`.
        unsafe {
            tipc_connect(file.as_raw_fd(), srv_name.as_ptr())?;
        }