Skip to content

Commit 565b122

Browse files
committed
fix: 修复 clippy 错误
1 parent ee40970 commit 565b122

4 files changed

Lines changed: 11 additions & 22 deletions

File tree

src/api_impl/hook.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,16 @@ pub unsafe extern "C" fn api_hook_create(
3636
pub unsafe extern "C" fn api_hook_enable(target: *mut c_void) -> i32 {
3737
let hooks = HOOKS.lock().unwrap();
3838
match hooks.get(&(target as usize)) {
39-
Some(entry) => {
40-
if entry.detour.enable().is_ok() {
41-
0
42-
} else {
43-
-1
44-
}
45-
}
46-
None => -1,
39+
Some(entry) if entry.detour.enable().is_ok() => 0,
40+
_ => -1,
4741
}
4842
}
4943

5044
pub unsafe extern "C" fn api_hook_disable(target: *mut c_void) -> i32 {
5145
let hooks = HOOKS.lock().unwrap();
5246
match hooks.get(&(target as usize)) {
53-
Some(entry) => {
54-
if entry.detour.disable().is_ok() {
55-
0
56-
} else {
57-
-1
58-
}
59-
}
60-
None => -1,
47+
Some(entry) if entry.detour.disable().is_ok() => 0,
48+
_ => -1,
6149
}
6250
}
6351

src/api_impl/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub unsafe extern "C" fn api_aob_scan(
2020
for i in 0..=(size as usize - len) {
2121
let mem = start + i;
2222
let mut ok = true;
23-
for j in 0..len {
24-
if mask_bytes[j] == b'x' && *((mem + j) as *const u8) != *pat.add(j) {
23+
for (j, &m) in mask_bytes.iter().enumerate() {
24+
if m == b'x' && *((mem + j) as *const u8) != *pat.add(j) {
2525
ok = false;
2626
break;
2727
}

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(non_snake_case)]
1+
#![allow(non_snake_case, clippy::manual_c_str_literals, clippy::upper_case_acronyms)]
22
#![feature(c_variadic)]
33

44
mod api_impl;
@@ -45,6 +45,7 @@ unsafe extern "system" fn DllMain(h_module: HMODULE, reason: u32, _reserved: *mu
4545
std::ptr::null_mut(),
4646
);
4747
}
48+
#[allow(clippy::collapsible_match)]
4849
DLL_PROCESS_DETACH => {
4950
// _reserved 非 NULL = 进程正在终止 (ExitProcess)
5051
// 此时不能等待线程或做复杂清理,OS 会回收所有资源

src/loader/crash_dump.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ unsafe extern "system" fn unhandled_exception_filter(exception: *mut EXCEPTION_P
7070
unsafe fn write_crash_report(exception: *mut EXCEPTION_POINTERS) -> Result<(), String> {
7171
let base_dir = get_self_base_dir().ok_or_else(|| "cannot resolve base dir".to_string())?;
7272
let crash_dir = format!("{}\\mods\\crash", base_dir);
73-
CreateDirectoryA(format!("{}\0", format!("{}\\mods", base_dir)).as_ptr(), null());
73+
CreateDirectoryA(format!("{}\\mods\0", base_dir).as_ptr(), null());
7474
CreateDirectoryA(format!("{}\0", crash_dir).as_ptr(), null());
7575

7676
let stamp = timestamp();
@@ -98,7 +98,7 @@ unsafe fn write_minidump(path: &str, exception: *mut EXCEPTION_POINTERS) -> Resu
9898
return Err(format!("CreateFileA failed for {}", path));
9999
}
100100

101-
let mut exception_info = MINIDUMP_EXCEPTION_INFORMATION {
101+
let exception_info = MINIDUMP_EXCEPTION_INFORMATION {
102102
ThreadId: GetCurrentThreadId(),
103103
ExceptionPointers: exception,
104104
ClientPointers: 0,
@@ -108,7 +108,7 @@ unsafe fn write_minidump(path: &str, exception: *mut EXCEPTION_POINTERS) -> Resu
108108
GetCurrentProcessId(),
109109
file,
110110
MiniDumpNormal,
111-
&mut exception_info,
111+
&exception_info,
112112
null_mut(),
113113
null_mut(),
114114
);

0 commit comments

Comments
 (0)