Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aarkegz committed Dec 21, 2024
1 parent e536257 commit eb27d16
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
1 change: 1 addition & 0 deletions api/arceos_posix_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ pub unsafe fn sys_lstat(path: *const c_char, buf: *mut ctypes::stat) -> ctypes::
}

/// Get the path of the current directory.
#[allow(clippy::unnecessary_cast)] // `c_char` is either `i8` or `u8`
pub fn sys_getcwd(buf: *mut c_char, size: usize) -> *mut c_char {
debug!("sys_getcwd <= {:#x} {}", buf as usize, size);
syscall_body!(sys_getcwd, {
Expand Down
4 changes: 2 additions & 2 deletions examples/shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ fn path_to_str(path: &impl AsRef<std::ffi::OsStr>) -> &str {
}

#[cfg(feature = "axstd")]
fn path_to_str(path: &std::string::String) -> &str {
path.as_str()
fn path_to_str(path: &str) -> &str {
path
}

mod cmd;
Expand Down
28 changes: 13 additions & 15 deletions modules/axhal/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,19 @@ pub fn current_task_ptr<T>() -> *const T {
/// The given `ptr` must be pointed to a valid task structure.
#[inline]
pub unsafe fn set_current_task_ptr<T>(ptr: *const T) {
unsafe {
#[cfg(target_arch = "x86_64")]
{
CURRENT_TASK_PTR.write_current_raw(ptr as usize)
}
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
{
let _guard = kernel_guard::IrqSave::new();
CURRENT_TASK_PTR.write_current_raw(ptr as usize)
}
#[cfg(target_arch = "aarch64")]
{
use tock_registers::interfaces::Writeable;
aarch64_cpu::registers::SP_EL0.set(ptr as u64)
}
#[cfg(target_arch = "x86_64")]
{
unsafe { CURRENT_TASK_PTR.write_current_raw(ptr as usize) }
}
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
{
let _guard = kernel_guard::IrqSave::new();
unsafe { CURRENT_TASK_PTR.write_current_raw(ptr as usize) }
}
#[cfg(target_arch = "aarch64")]
{
use tock_registers::interfaces::Writeable;
aarch64_cpu::registers::SP_EL0.set(ptr as u64)
}
}

Expand Down
17 changes: 13 additions & 4 deletions ulib/axlibc/src/strftime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ impl<T: Write> Write for CountingWriter<T> {
}
}

#[inline]
fn c_char_as_u8(c: c_char) -> u8 {
#[allow(clippy::unnecessary_cast)]
{
c as u8
}
}

unsafe fn strftime_inner<W: WriteByte>(
w: W,
format: *const c_char,
Expand Down Expand Up @@ -164,20 +172,20 @@ unsafe fn strftime_inner<W: WriteByte>(
];

while *format != 0 {
if *format as u8 != b'%' {
w!(byte * format as u8);
if c_char_as_u8(*format) != b'%' {
w!(byte c_char_as_u8(*format));
format = format.offset(1);
continue;
}

format = format.offset(1);

if *format as u8 == b'E' || *format as u8 == b'O' {
if c_char_as_u8(*format) == b'E' || c_char_as_u8(*format) == b'O' {
// Ignore because these do nothing without locale
format = format.offset(1);
}

match *format as u8 {
match c_char_as_u8(*format) {
b'%' => w!(byte b'%'),
b'n' => w!(byte b'\n'),
b't' => w!(byte b'\t'),
Expand Down Expand Up @@ -239,6 +247,7 @@ unsafe fn strftime_inner<W: WriteByte>(

/// Convert date and time to a string.
#[unsafe(no_mangle)]
#[allow(clippy::unnecessary_cast)] // casting c_char to u8, c_char is either i8 or u8
pub unsafe extern "C" fn strftime(
buf: *mut c_char,
size: ctypes::size_t,
Expand Down

0 comments on commit eb27d16

Please sign in to comment.