diff --git a/Cargo.toml b/Cargo.toml index 2ed76957e1..dcf6c01ec1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,11 +33,12 @@ dangling_pointers_from_temporaries = "deny" irrefutable_let_patterns = "deny" mismatched_lifetime_syntaxes = "deny" non_camel_case_types = "allow" -non_snake_case = "allow" -non_upper_case_globals = "allow" +non_snake_case = "allow" # TODO review occuurences +non_upper_case_globals = "allow" # TODO review occuurences unpredictable_function_pointer_comparisons = "deny" unsafe_op_in_unsafe_fn = "deny" unused_imports = "deny" +unused_must_use = "deny" unused_mut = "deny" unused_unsafe = "deny" unused_variables = "allow" # TODO review occurrences (too many for now) diff --git a/src/header/glob/mod.rs b/src/header/glob/mod.rs index e71561a9d0..72e5010d5f 100644 --- a/src/header/glob/mod.rs +++ b/src/header/glob/mod.rs @@ -164,7 +164,7 @@ pub unsafe extern "C" fn globfree(pglob: *mut glob_t) { } if !path.is_null() { unsafe { - CString::from_raw(path); + drop(CString::from_raw(path)); } } } diff --git a/src/header/netdb/dns/mod.rs b/src/header/netdb/dns/mod.rs index 2d73281b61..9d7e44bd1c 100644 --- a/src/header/netdb/dns/mod.rs +++ b/src/header/netdb/dns/mod.rs @@ -132,8 +132,8 @@ impl Dns { let flags = pop_n16!(); let queries_len = pop_n16!(); let answers_len = pop_n16!(); - pop_n16!(); - pop_n16!(); + let _ = pop_n16!(); + let _ = pop_n16!(); let mut queries = Vec::new(); for _query_i in 0..queries_len { diff --git a/src/header/netdb/host.rs b/src/header/netdb/host.rs index 59ad6190a1..73e3604592 100644 --- a/src/header/netdb/host.rs +++ b/src/header/netdb/host.rs @@ -37,7 +37,7 @@ pub static mut HOST_STAYOPEN: c_int = 0; #[unsafe(no_mangle)] pub unsafe extern "C" fn endhostent() { if unsafe { HOSTDB } >= 0 { - Sys::close(unsafe { HOSTDB }); + if let Ok(()) = Sys::close(unsafe { HOSTDB }) {}; // TODO handle error } unsafe { HOSTDB = -1 }; } @@ -48,7 +48,7 @@ pub unsafe extern "C" fn sethostent(stayopen: c_int) { if unsafe { HOSTDB } < 0 { unsafe { HOSTDB = Sys::open(c"/etc/hosts".into(), O_RDONLY, 0).or_minus_one_errno() } } else { - Sys::lseek(unsafe { HOSTDB }, 0, SEEK_SET); + if let Ok(_) = Sys::lseek(unsafe { HOSTDB }, 0, SEEK_SET) {}; // TODO handle error } unsafe { H_POS = 0 }; } diff --git a/src/header/netdb/lookup.rs b/src/header/netdb/lookup.rs index c5da3fd320..7c8e405aaa 100644 --- a/src/header/netdb/lookup.rs +++ b/src/header/netdb/lookup.rs @@ -39,10 +39,10 @@ pub fn lookup_host(host: &str) -> Result { if let Some(dns_addr) = parse_ipv4_string(&dns_string) { let mut timespec = timespec::default(); - Sys::clock_gettime( + if let Ok(()) = Sys::clock_gettime( time::constants::CLOCK_REALTIME, Out::from_mut(&mut timespec), - ); + ) {}; // TODO handle error let tid = (timespec.tv_nsec >> 16) as u16; let packet = Dns { @@ -76,14 +76,14 @@ pub fn lookup_host(host: &str) -> Result { return Err(EIO); } if sys_socket::send(sock, packet_data_ptr, packet_data_len, 0) < 0 { - Box::from_raw(packet_data_ptr); + drop(Box::from_raw(packet_data_ptr)); return Err(EIO); } sock }; unsafe { - Box::from_raw(packet_data_ptr); + drop(Box::from_raw(packet_data_ptr)); } let i = 0 as socklen_t; @@ -141,10 +141,10 @@ pub fn lookup_addr(addr: in_addr) -> Result>, c_int> { ); let mut timespec = timespec::default(); - Sys::clock_gettime( + if let Ok(()) = Sys::clock_gettime( time::constants::CLOCK_REALTIME, Out::from_mut(&mut timespec), - ); + ) {}; // TODO handle error let tid = (timespec.tv_nsec >> 16) as u16; let packet = Dns { @@ -187,7 +187,7 @@ pub fn lookup_addr(addr: in_addr) -> Result>, c_int> { } unsafe { - Box::from_raw(packet_data_ptr); + drop(Box::from_raw(packet_data_ptr)); } let i = mem::size_of::() as socklen_t; diff --git a/src/header/netdb/mod.rs b/src/header/netdb/mod.rs index 8629270e42..42635c4e5d 100644 --- a/src/header/netdb/mod.rs +++ b/src/header/netdb/mod.rs @@ -181,21 +181,21 @@ fn bytes_to_box_str(bytes: &[u8]) -> Box { /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn endnetent() { - Sys::close(unsafe { NETDB }); + if let Ok(()) = Sys::close(unsafe { NETDB }) {}; // TODO handle error unsafe { NETDB = 0 }; } /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn endprotoent() { - Sys::close(unsafe { PROTODB }); + if let Ok(()) = Sys::close(unsafe { PROTODB }) {}; // TODO handle error unsafe { PROTODB = 0 }; } /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn endservent() { - Sys::close(unsafe { SERVDB }); + if let Ok(()) = Sys::close(unsafe { SERVDB }) {}; // TODO handle error unsafe { SERVDB = 0 }; } @@ -783,7 +783,7 @@ pub unsafe extern "C" fn setnetent(stayopen: c_int) { if unsafe { NETDB } == 0 { unsafe { NETDB = Sys::open(c"/etc/networks".into(), O_RDONLY, 0).or_minus_one_errno() } } else { - Sys::lseek(unsafe { NETDB }, 0, SEEK_SET); + if let Ok(_) = Sys::lseek(unsafe { NETDB }, 0, SEEK_SET) {}; // TODO handle errror unsafe { N_POS = 0 }; } } @@ -795,7 +795,7 @@ pub unsafe extern "C" fn setprotoent(stayopen: c_int) { if unsafe { PROTODB } == 0 { unsafe { PROTODB = Sys::open(c"/etc/protocols".into(), O_RDONLY, 0).or_minus_one_errno() } } else { - Sys::lseek(unsafe { PROTODB }, 0, SEEK_SET); + if let Ok(_) = Sys::lseek(unsafe { PROTODB }, 0, SEEK_SET) {}; // TODO handle error unsafe { P_POS = 0 }; } } @@ -807,7 +807,7 @@ pub unsafe extern "C" fn setservent(stayopen: c_int) { if unsafe { SERVDB } == 0 { unsafe { SERVDB = Sys::open(c"/etc/services".into(), O_RDONLY, 0).or_minus_one_errno() } } else { - Sys::lseek(unsafe { SERVDB }, 0, SEEK_SET); + if let Ok(_) = Sys::lseek(unsafe { SERVDB }, 0, SEEK_SET) {}; // TODO handle error unsafe { S_POS = 0 }; } } @@ -1030,9 +1030,9 @@ pub unsafe extern "C" fn freeaddrinfo(res: *mut addrinfo) { } if !bai.ai_addr.is_null() { if bai.ai_addrlen == mem::size_of::() as socklen_t { - unsafe { Box::from_raw(bai.ai_addr as *mut sockaddr_in) }; + unsafe { drop(Box::from_raw(bai.ai_addr as *mut sockaddr_in)) }; } else if bai.ai_addrlen == mem::size_of::() as socklen_t { - unsafe { Box::from_raw(bai.ai_addr as *mut sockaddr_in6) }; + unsafe { drop(Box::from_raw(bai.ai_addr as *mut sockaddr_in6)) }; } else { todo_skip!(0, "freeaddrinfo: unknown ai_addrlen {}", bai.ai_addrlen); } diff --git a/src/header/pty/linux.rs b/src/header/pty/linux.rs index 5c580d612d..2ee23cc9e6 100644 --- a/src/header/pty/linux.rs +++ b/src/header/pty/linux.rs @@ -38,7 +38,7 @@ pub(super) unsafe fn openpty(name: &mut [u8]) -> Result<(c_int, c_int), ()> { } let mut cursor = Cursor::new(name); - write!(cursor, "/dev/pts/{}\0", ptn); + if let Ok(()) = write!(cursor, "/dev/pts/{}\0", ptn) {}; // TODO handle error let slave = unsafe { fcntl::open( diff --git a/src/header/regex/mod.rs b/src/header/regex/mod.rs index 5978dddc24..50d645fc60 100644 --- a/src/header/regex/mod.rs +++ b/src/header/regex/mod.rs @@ -90,7 +90,7 @@ pub unsafe extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags: #[unsafe(no_mangle)] #[linkage = "weak"] // redefined in GIT pub unsafe extern "C" fn regfree(regex: *mut regex_t) { - unsafe { Box::from_raw((*regex).ptr) }; + unsafe { drop(Box::from_raw((*regex).ptr)) }; } /// See . diff --git a/src/header/semaphore/mod.rs b/src/header/semaphore/mod.rs index 0dcf2144b1..59d94f84ca 100644 --- a/src/header/semaphore/mod.rs +++ b/src/header/semaphore/mod.rs @@ -81,7 +81,7 @@ pub unsafe extern "C" fn sem_unlink(name: *const c_char) -> c_int { /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn sem_wait(sem: *mut sem_t) -> c_int { - unsafe { get(sem) }.wait(None, CLOCK_MONOTONIC); + if let Ok(()) = unsafe { get(sem) }.wait(None, CLOCK_MONOTONIC) {}; // TODO handle error 0 } @@ -93,7 +93,7 @@ pub unsafe extern "C" fn sem_clockwait( clock_id: clockid_t, abstime: *const timespec, ) -> c_int { - unsafe { get(sem) }.wait(Some(&unsafe { *abstime }), clock_id); + if let Ok(()) = unsafe { get(sem) }.wait(Some(&unsafe { *abstime }), clock_id) {}; // TODO handle error 0 } @@ -101,7 +101,7 @@ pub unsafe extern "C" fn sem_clockwait( /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn sem_timedwait(sem: *mut sem_t, abstime: *const timespec) -> c_int { - unsafe { get(sem) }.wait(Some(&unsafe { *abstime }), CLOCK_REALTIME); + if let Ok(()) = unsafe { get(sem) }.wait(Some(&unsafe { *abstime }), CLOCK_REALTIME) {}; // TODO handle error 0 } diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index 45c128b9b9..fa9bb72aa0 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -580,7 +580,7 @@ pub unsafe extern "C" fn fopen(filename: *const c_char, mode: *const c_char) -> .map(|f| Box::into_raw(f)) .map_err(|err| { // TODO: guard type - Sys::close(fd); + if let Ok(()) = Sys::close(fd) {}; // TODO handle error err }) .or_errno_null_mut() @@ -1320,11 +1320,11 @@ pub unsafe extern "C" fn tmpfile() -> *mut FILE { let fp = unsafe { fdopen(fd, c"w+".as_ptr()) }; { let file_name = unsafe { CStr::from_ptr(file_name) }; - Sys::unlink(file_name); + if let Ok(()) = Sys::unlink(file_name) {}; // TODO handle error } if fp.is_null() { - Sys::close(fd); + if let Ok(()) = Sys::close(fd) {}; // TODO handle error } fp diff --git a/src/header/stdio/printf.rs b/src/header/stdio/printf.rs index 33c8414dff..22d8cb8f8e 100644 --- a/src/header/stdio/printf.rs +++ b/src/header/stdio/printf.rs @@ -697,7 +697,7 @@ pub(crate) unsafe fn inner_printf( } else { // TODO: wcsrtombs wrapper for c in text.iter().filter_map(|u| char::from_u32((*u).into())) { - write!(w, "{}", c); + if let Ok(()) = write!(w, "{}", c) {}; // TODO handle error } } continue; diff --git a/src/header/sys_stat/mod.rs b/src/header/sys_stat/mod.rs index bbccc3613b..c9f559726d 100644 --- a/src/header/sys_stat/mod.rs +++ b/src/header/sys_stat/mod.rs @@ -157,7 +157,7 @@ pub unsafe extern "C" fn lstat(path: *const c_char, buf: *mut stat) -> c_int { // TODO: Rustify let res = Sys::fstat(fd, buf).map(|()| 0).or_minus_one_errno(); - Sys::close(fd); + if let Ok(()) = Sys::close(fd) {}; // TODO handle error res } @@ -230,7 +230,7 @@ pub unsafe extern "C" fn stat(file: *const c_char, buf: *mut stat) -> c_int { // TODO: Rustify let res = Sys::fstat(fd, buf).map(|()| 0).or_minus_one_errno(); - Sys::close(fd); + if let Ok(()) = Sys::close(fd) {}; // TODO handle error res } diff --git a/src/header/sys_statvfs/mod.rs b/src/header/sys_statvfs/mod.rs index a48d924311..866768b885 100644 --- a/src/header/sys_statvfs/mod.rs +++ b/src/header/sys_statvfs/mod.rs @@ -52,7 +52,7 @@ pub unsafe extern "C" fn statvfs(file: *const c_char, buf: *mut statvfs) -> c_in let res = Sys::fstatvfs(fd, buf).map(|()| 0).or_minus_one_errno(); - Sys::close(fd); + if let Ok(()) = Sys::close(fd) {}; // TODO handle error res } diff --git a/src/header/sys_syslog/mod.rs b/src/header/sys_syslog/mod.rs index 976151e001..f2277cd740 100644 --- a/src/header/sys_syslog/mod.rs +++ b/src/header/sys_syslog/mod.rs @@ -111,7 +111,7 @@ pub unsafe extern "C" fn openlog(ident: *const c_char, opt: c_int, facility: c_i // Ensure log is ready to write now instead of checking on the first message. if conf.contains(logger::Config::NoDelay) { - params.open_logger(); + if let Ok(()) = params.open_logger() {}; // TODO handle error } } diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 6facf6a046..e7114e2d59 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -1060,7 +1060,7 @@ pub unsafe extern "C" fn symlink(path1: *const c_char, path2: *const c_char) -> /// See . #[unsafe(no_mangle)] pub extern "C" fn sync() { - Sys::sync(); + if let Ok(()) = Sys::sync() {}; // TODO handle error } /// See . @@ -1094,7 +1094,7 @@ pub unsafe extern "C" fn truncate(path: *const c_char, length: off_t) -> c_int { let res = ftruncate(fd, length); - Sys::close(fd); + if let Ok(()) = Sys::close(fd) {}; // TODO handle error res } diff --git a/src/header/unistd/sysconf/redox.rs b/src/header/unistd/sysconf/redox.rs index 651b43adbf..140427edb1 100644 --- a/src/header/unistd/sysconf/redox.rs +++ b/src/header/unistd/sysconf/redox.rs @@ -97,7 +97,7 @@ pub fn get_mem_stat() -> Result { let fd = Sys::open(c"/scheme/memory".into(), fcntl::O_PATH, 0)?; let mut buf = sys_statvfs::statvfs::default(); let res = Sys::fstatvfs(fd, Out::from_mut(&mut buf)); - Sys::close(fd); + if let Ok(()) = Sys::close(fd) {}; // TODO handle error let _ = res?; return Ok(buf); } diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 48faaf4000..d8df40e86a 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -108,14 +108,14 @@ impl FileWriter { impl fmt::Write for FileWriter { fn write_str(&mut self, s: &str) -> fmt::Result { - self.write(s.as_bytes()); + if let Ok(()) = self.write(s.as_bytes()) {}; // TODO handle error Ok(()) } } impl WriteByte for FileWriter { fn write_u8(&mut self, byte: u8) -> fmt::Result { - self.write(&[byte]); + if let Ok(()) = self.write(&[byte]) {}; // TODO handle error Ok(()) } } diff --git a/src/platform/redox/ptrace.rs b/src/platform/redox/ptrace.rs index a8668be624..d9a110e021 100644 --- a/src/platform/redox/ptrace.rs +++ b/src/platform/redox/ptrace.rs @@ -167,7 +167,7 @@ unsafe fn inner_ptrace( | sys_ptrace::PTRACE_SYSCALL | sys_ptrace::PTRACE_SYSEMU | sys_ptrace::PTRACE_SYSEMU_SINGLESTEP => { - Sys::kill(pid, signal::SIGCONT as _); + if let Ok(()) = Sys::kill(pid, signal::SIGCONT as _) {}; // TODO handle error // TODO: Translate errors let syscall = syscall::PTRACE_STOP_PRE_SYSCALL | syscall::PTRACE_STOP_POST_SYSCALL; diff --git a/src/sync/barrier.rs b/src/sync/barrier.rs index 9ae84a60ef..6204a235ef 100644 --- a/src/sync/barrier.rs +++ b/src/sync/barrier.rs @@ -40,7 +40,7 @@ impl Barrier { if guard.count == self.original_count.get() { guard.gen_id = guard.gen_id.wrapping_add(1); guard.count = 0; - self.cvar.broadcast(); + if let Ok(()) = self.cvar.broadcast() {}; // TODO handle error drop(guard); diff --git a/src/sync/mod.rs b/src/sync/mod.rs index 4a1ffc8498..cd818df549 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -137,11 +137,10 @@ pub fn rttime() -> timespec { unsafe { let mut time = MaybeUninit::uninit(); - // TODO: Handle error - Sys::clock_gettime( + if let Ok(()) = Sys::clock_gettime( crate::header::time::CLOCK_REALTIME, Out::from_uninit_mut(&mut time), - ); + ) {}; // TODO handle error time.assume_init() }