From 4b627399256acb43a59b303740a65cdd42227002 Mon Sep 17 00:00:00 2001 From: jwx1282937 Date: Thu, 14 Dec 2023 03:28:04 +0000 Subject: [PATCH] fix: rectify reorder Signed-off-by: jwx1282937 --- example/rust_test/service/src/lib.rs | 4 ++-- interfaces/innerkits/rust/src/ashmem.rs | 6 ++--- .../innerkits/rust/src/ipc/remote_obj/cmp.rs | 2 +- .../innerkits/rust/src/ipc/remote_stub.rs | 7 ++++-- interfaces/innerkits/rust/src/lib.rs | 23 ++++++++++--------- interfaces/innerkits/rust/src/parcel/mod.rs | 2 +- .../innerkits/rust/src/parcel/parcelable.rs | 5 +++- .../innerkits/rust/src/parcel/types/boxt.rs | 4 ++-- .../rust/src/parcel/types/file_desc.rs | 5 +++- .../rust/src/parcel/types/integer.rs | 5 +++- .../rust/src/parcel/types/interface_token.rs | 5 +++- .../rust/src/parcel/types/string16.rs | 5 +++- .../rust/src/parcel/types/strings.rs | 4 ++-- interfaces/innerkits/rust/src/process.rs | 5 ++-- .../test/unittest/rust/service/src/lib.rs | 4 ++-- 15 files changed, 53 insertions(+), 33 deletions(-) diff --git a/example/rust_test/service/src/lib.rs b/example/rust_test/service/src/lib.rs index ad49d246..316f5aec 100644 --- a/example/rust_test/service/src/lib.rs +++ b/example/rust_test/service/src/lib.rs @@ -20,8 +20,8 @@ extern crate ipc_rust; mod access_token; use ipc_rust::{ - IRemoteBroker, IRemoteObj, RemoteStub, IpcResult, IpcStatusCode, - RemoteObj, define_remote_object, FIRST_CALL_TRANSACTION, + IRemoteBroker, IRemoteObj, RemoteStub, IpcResult, + IpcStatusCode, RemoteObj, define_remote_object, FIRST_CALL_TRANSACTION, }; use ipc_rust::{ MsgParcel, BorrowedMsgParcel, diff --git a/interfaces/innerkits/rust/src/ashmem.rs b/interfaces/innerkits/rust/src/ashmem.rs index e4df51bf..72e63ece 100644 --- a/interfaces/innerkits/rust/src/ashmem.rs +++ b/interfaces/innerkits/rust/src/ashmem.rs @@ -14,8 +14,8 @@ */ use crate::{ - ipc_binding, RawData, IpcResult, IpcStatusCode, BorrowedMsgParcel, status_result, - AsRawPtr + ipc_binding, RawData, IpcResult, IpcStatusCode, + BorrowedMsgParcel, status_result, AsRawPtr }; use crate::ipc_binding::CAshmem; use std::ffi::{CString, c_char}; @@ -153,7 +153,7 @@ impl Ashmem { /// Write data to ashmem pub fn write(&self, data: &[u8], offset: i32) -> bool { let len = data.len() as i32; - if offset < 0 || offset >= len { + if (offset < 0) || (offset >= len) { error!(LOG_LABEL, "invalid offset: {}, len: {}", offset, len); return false; } diff --git a/interfaces/innerkits/rust/src/ipc/remote_obj/cmp.rs b/interfaces/innerkits/rust/src/ipc/remote_obj/cmp.rs index 010b0e82..125533fb 100644 --- a/interfaces/innerkits/rust/src/ipc/remote_obj/cmp.rs +++ b/interfaces/innerkits/rust/src/ipc/remote_obj/cmp.rs @@ -28,7 +28,7 @@ impl Ord for RemoteObj { let greater_than = unsafe { ipc_binding::RemoteObjectLessThan(other.0.as_ptr(), self.0.as_ptr()) }; - if !less_than && !greater_than { + if (!less_than) && (!greater_than) { Ordering::Equal } else if less_than { Ordering::Less diff --git a/interfaces/innerkits/rust/src/ipc/remote_stub.rs b/interfaces/innerkits/rust/src/ipc/remote_stub.rs index 03021372..6fa6d048 100644 --- a/interfaces/innerkits/rust/src/ipc/remote_stub.rs +++ b/interfaces/innerkits/rust/src/ipc/remote_stub.rs @@ -19,8 +19,11 @@ use crate::{ }; use crate::ipc_binding::{CRemoteObject, CParcel}; use std::ffi::{c_void, CString, c_char}; -use std::ops::{Deref}; -use hilog_rust::{info, error, hilog, HiLogLabel, LogType}; +use std::ops::Deref; +use hilog_rust::{ + info, error, hilog, HiLogLabel, + LogType +}; const LOG_LABEL: HiLogLabel = HiLogLabel { log_type: LogType::LogCore, diff --git a/interfaces/innerkits/rust/src/lib.rs b/interfaces/innerkits/rust/src/lib.rs index da4857a2..8f8f8187 100644 --- a/interfaces/innerkits/rust/src/lib.rs +++ b/interfaces/innerkits/rust/src/lib.rs @@ -26,12 +26,12 @@ mod ashmem; // Export types of this crate pub use crate::errors::{IpcResult, status_result, IpcStatusCode, parse_status_code}; pub use crate::ipc::{ - IRemoteBroker, IRemoteObj, IRemoteStub, FromRemoteObj, RemoteObjRef, - remote_obj::RemoteObj, remote_obj::death_recipient::DeathRecipient, - remote_stub::RemoteStub, + IRemoteBroker, IRemoteObj, IRemoteStub, FromRemoteObj, + RemoteObjRef, remote_obj::RemoteObj, remote_obj::death_recipient::DeathRecipient,remote_stub::RemoteStub, }; pub use crate::ipc_async::{ - IpcAsyncPool, IpcAsyncRuntime, ToAsyncIpc, ToSyncIpc, BoxFuture, Ylong, Runtime, + IpcAsyncPool, IpcAsyncRuntime, ToAsyncIpc, ToSyncIpc, + BoxFuture, Ylong, Runtime, }; pub use crate::parcel::{ @@ -40,17 +40,18 @@ pub use crate::parcel::{ }; pub use crate::parcel::parcelable::{SerArray, DeArray}; pub use crate::parcel::types::{ - interface_token::InterfaceToken, file_desc::FileDesc, - string16::String16 + interface_token::InterfaceToken, file_desc::FileDesc, string16::String16 }; pub use crate::ashmem::{ - Ashmem, PROT_NONE, PROT_READ, PROT_WRITE, PROT_EXEC, + Ashmem, PROT_NONE, PROT_READ, PROT_WRITE, + PROT_EXEC, }; pub use crate::process::{ - get_context_object, add_service, get_service, join_work_thread, stop_work_thread, - get_calling_uid, get_calling_token_id, get_first_token_id, get_self_token_id, - get_calling_pid, set_max_work_thread, is_local_calling, set_calling_identity, - get_local_device_id, get_calling_device_id, reset_calling_identity, is_handling_transaction, + get_context_object, add_service, get_service, join_work_thread, + stop_work_thread, get_calling_uid, get_calling_token_id, get_first_token_id, + get_self_token_id, get_calling_pid, set_max_work_thread, is_local_calling, + set_calling_identity, get_local_device_id, get_calling_device_id, reset_calling_identity, + is_handling_transaction, }; pub use crate::ipc_binding::{CRemoteObject, CIRemoteObject}; diff --git a/interfaces/innerkits/rust/src/parcel/mod.rs b/interfaces/innerkits/rust/src/parcel/mod.rs index 805d28c4..735c4785 100644 --- a/interfaces/innerkits/rust/src/parcel/mod.rs +++ b/interfaces/innerkits/rust/src/parcel/mod.rs @@ -263,7 +263,7 @@ impl RawData{ /// The caller should ensure that the u8 slice can be /// correctly converted to other rust types pub fn read(&self, start: u32, len: u32) -> IpcResult<&[u8]> { - if len == 0 || len > self.len || start >= self.len || (start + len) > self.len { + if (len == 0) || (len > self.len) || (start >= self.len) || ((start + len) > self.len) { return Err(IpcStatusCode::Failed); } // SAFETY: diff --git a/interfaces/innerkits/rust/src/parcel/parcelable.rs b/interfaces/innerkits/rust/src/parcel/parcelable.rs index 513b53af..013f3ed4 100644 --- a/interfaces/innerkits/rust/src/parcel/parcelable.rs +++ b/interfaces/innerkits/rust/src/parcel/parcelable.rs @@ -13,7 +13,10 @@ * limitations under the License. */ -use crate::{IpcResult, IpcStatusCode, status_result, BorrowedMsgParcel, ipc_binding, AsRawPtr}; +use crate::{ + IpcResult, IpcStatusCode, status_result, BorrowedMsgParcel, + ipc_binding, AsRawPtr +}; use std::mem::MaybeUninit; use std::ffi::{c_void, c_ulong}; use std::ptr; diff --git a/interfaces/innerkits/rust/src/parcel/types/boxt.rs b/interfaces/innerkits/rust/src/parcel/types/boxt.rs index 480e6cd1..7a538fe3 100644 --- a/interfaces/innerkits/rust/src/parcel/types/boxt.rs +++ b/interfaces/innerkits/rust/src/parcel/types/boxt.rs @@ -17,7 +17,7 @@ use super::*; impl Serialize for Box { fn serialize(&self, parcel: &mut BorrowedMsgParcel<'_>) -> IpcResult<()> { - Serialize::serialize(&**self, parcel) + Serialize::serialize(&(**self), parcel) } } @@ -29,7 +29,7 @@ impl Deserialize for Box { impl SerOption for Box { fn ser_option(this: Option<&Self>, parcel: &mut BorrowedMsgParcel<'_>) -> IpcResult<()> { - SerOption::ser_option(this.map(|inner| &**inner), parcel) + SerOption::ser_option(this.map(|inner| &(**inner)), parcel) } } diff --git a/interfaces/innerkits/rust/src/parcel/types/file_desc.rs b/interfaces/innerkits/rust/src/parcel/types/file_desc.rs index 529f83f8..68d41ae1 100644 --- a/interfaces/innerkits/rust/src/parcel/types/file_desc.rs +++ b/interfaces/innerkits/rust/src/parcel/types/file_desc.rs @@ -14,7 +14,10 @@ */ use super::*; -use crate::{ipc_binding, BorrowedMsgParcel, AsRawPtr, status_result, IpcResult, IpcStatusCode}; +use crate::{ + ipc_binding, BorrowedMsgParcel, AsRawPtr, status_result, + IpcResult, IpcStatusCode +}; use std::fs::File; use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; diff --git a/interfaces/innerkits/rust/src/parcel/types/integer.rs b/interfaces/innerkits/rust/src/parcel/types/integer.rs index 66eae906..e7840273 100644 --- a/interfaces/innerkits/rust/src/parcel/types/integer.rs +++ b/interfaces/innerkits/rust/src/parcel/types/integer.rs @@ -14,7 +14,10 @@ */ use super::*; -use crate::{ipc_binding, BorrowedMsgParcel, IpcResult, status_result, AsRawPtr}; +use crate::{ + ipc_binding, BorrowedMsgParcel, IpcResult, status_result, + AsRawPtr +}; use std::mem::MaybeUninit; impl_serde_option_for_parcelable!(i8, u8, i16, u16, i32, u32, i64, u64, f32,f64); diff --git a/interfaces/innerkits/rust/src/parcel/types/interface_token.rs b/interfaces/innerkits/rust/src/parcel/types/interface_token.rs index ff7a95f4..b663e698 100644 --- a/interfaces/innerkits/rust/src/parcel/types/interface_token.rs +++ b/interfaces/innerkits/rust/src/parcel/types/interface_token.rs @@ -14,7 +14,10 @@ */ use super::*; -use crate::{ipc_binding, BorrowedMsgParcel, IpcResult, IpcStatusCode, AsRawPtr, status_result}; +use crate::{ + ipc_binding, BorrowedMsgParcel, IpcResult, IpcStatusCode, + AsRawPtr, status_result +}; use std::convert::TryInto; use std::ffi::{CString, c_char}; use hilog_rust::{error, hilog, HiLogLabel, LogType}; diff --git a/interfaces/innerkits/rust/src/parcel/types/string16.rs b/interfaces/innerkits/rust/src/parcel/types/string16.rs index 94003a89..03fcd377 100644 --- a/interfaces/innerkits/rust/src/parcel/types/string16.rs +++ b/interfaces/innerkits/rust/src/parcel/types/string16.rs @@ -14,7 +14,10 @@ */ use super::*; -use crate::{ipc_binding, BorrowedMsgParcel, IpcResult, IpcStatusCode, status_result, AsRawPtr}; +use crate::{ + ipc_binding, BorrowedMsgParcel, IpcResult, IpcStatusCode, + status_result, AsRawPtr +}; use std::convert::TryInto; use std::mem::MaybeUninit; use std::ffi::CString; diff --git a/interfaces/innerkits/rust/src/parcel/types/strings.rs b/interfaces/innerkits/rust/src/parcel/types/strings.rs index bf0e1c3e..1eba5d44 100644 --- a/interfaces/innerkits/rust/src/parcel/types/strings.rs +++ b/interfaces/innerkits/rust/src/parcel/types/strings.rs @@ -15,8 +15,8 @@ use super::*; use crate::{ - ipc_binding, BorrowedMsgParcel, IpcResult, IpcStatusCode, status_result, - AsRawPtr + ipc_binding, BorrowedMsgParcel, IpcResult, IpcStatusCode, + status_result, AsRawPtr }; use std::convert::TryInto; use std::mem::MaybeUninit; diff --git a/interfaces/innerkits/rust/src/process.rs b/interfaces/innerkits/rust/src/process.rs index b2ceb9f9..2731176d 100644 --- a/interfaces/innerkits/rust/src/process.rs +++ b/interfaces/innerkits/rust/src/process.rs @@ -14,8 +14,9 @@ */ use crate::{ - ipc_binding, MsgParcel, RemoteObj, IRemoteObj, InterfaceToken, String16, - IpcResult, IpcStatusCode, parse_status_code, + ipc_binding, MsgParcel, RemoteObj, IRemoteObj, + InterfaceToken, String16, IpcResult, IpcStatusCode, + parse_status_code }; use crate::parcel::{vec_to_string, allocate_vec_with_buffer}; use std::ffi::{CString, c_char, c_void}; diff --git a/ipc/native/test/unittest/rust/service/src/lib.rs b/ipc/native/test/unittest/rust/service/src/lib.rs index 9f215ad9..ea1502f0 100644 --- a/ipc/native/test/unittest/rust/service/src/lib.rs +++ b/ipc/native/test/unittest/rust/service/src/lib.rs @@ -20,8 +20,8 @@ extern crate ipc_rust; mod access_token; use ipc_rust::{ - IRemoteBroker, IRemoteObj, RemoteStub, IpcResult, IpcStatusCode, - RemoteObj, define_remote_object, FIRST_CALL_TRANSACTION, + IRemoteBroker, IRemoteObj, RemoteStub, IpcResult, + IpcStatusCode, RemoteObj, define_remote_object, FIRST_CALL_TRANSACTION, }; use ipc_rust::{ MsgParcel, BorrowedMsgParcel, FileDesc, InterfaceToken,