diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7d015e3784f42beb0f6afbb59b6f9d68e977e16e..0c6d35091dd79fb04186eee488c56e3e98b740b7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -168,6 +168,8 @@ jobs: run: rustc --version - name: Verify Rust code format run: cd frontends/libretro && cargo fmt --all -- --check + - name: Verify Rust code linting + run: cd frontends/libretro && cargo clippy -- -D warnings -A unknown-lints - name: Run unit tests run: cd frontends/libretro && cargo test - name: Build development version diff --git a/frontends/libretro/src/lib.rs b/frontends/libretro/src/lib.rs index df2647aa798f083d6fb3270ae891ae9615ce757d..c7ba8d99367e9b6d1112ea837fdb6e154a97fcc2 100644 --- a/frontends/libretro/src/lib.rs +++ b/frontends/libretro/src/lib.rs @@ -365,16 +365,19 @@ pub extern "C" fn retro_cheat_reset() { emulator.reset_cheats(); } +/// # Safety +/// +/// This function should not be called only within Lib Retro context. #[no_mangle] -pub extern "C" fn retro_cheat_set(_index: c_uint, enabled: bool, code: *const c_char) { +pub unsafe extern "C" fn retro_cheat_set(_index: c_uint, enabled: bool, code: *const c_char) { debugln!("retro_cheat_set()"); // we'll just ignore cheats that are not enabled, Boytacean // does not support pre-loading cheats if !enabled { return; } - let emulator = unsafe { EMULATOR.as_mut().unwrap() }; - let code_c = unsafe { CStr::from_ptr(code) }; + let emulator = EMULATOR.as_mut().unwrap(); + let code_c = CStr::from_ptr(code); let code_s = code_c.to_string_lossy().into_owned(); emulator.add_cheat_code(&code_s).unwrap(); } diff --git a/frontends/sdl/src/main.rs b/frontends/sdl/src/main.rs index 4c5ffefb6a87268cd41d2a922705ea981ddfe57c..437e85ef85c1eda5b70accd365b81d3c37bcd746 100644 --- a/frontends/sdl/src/main.rs +++ b/frontends/sdl/src/main.rs @@ -788,7 +788,7 @@ fn main() { // in case the default ROM path is provided and the file does not // exist then fails gracefully let path = Path::new(&args.rom_path); - if &args.rom_path == DEFAULT_ROM_PATH && !path.exists() { + if args.rom_path == DEFAULT_ROM_PATH && !path.exists() { println!("No ROM file provided, please provide one using the --rom-path option"); return; }