Merge branch 'unused-unsafe' into 'master'
add unused-unsafe lint See merge request redox-os/relibc!978
This commit is contained in:
@@ -44,6 +44,8 @@ non_camel_case_types = "allow"
|
||||
unpredictable_function_pointer_comparisons = "deny"
|
||||
unsafe_op_in_unsafe_fn = "deny"
|
||||
unused_mut = "deny"
|
||||
unused_unsafe = "deny"
|
||||
unused_variables = "allow" # TODO review occurrences (too many for now)
|
||||
|
||||
[lints.rust]
|
||||
dangling_pointers_from_temporaries = "deny"
|
||||
@@ -52,6 +54,8 @@ non_camel_case_types = "allow"
|
||||
unpredictable_function_pointer_comparisons = "deny"
|
||||
unsafe_op_in_unsafe_fn = "deny"
|
||||
unused_mut = "deny"
|
||||
unused_unsafe = "deny"
|
||||
unused_variables = "allow" # TODO review occurrences (too many for now)
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1"
|
||||
|
||||
@@ -11,9 +11,8 @@ use crate::{
|
||||
error::{Errno, ResultExt, ResultExtPtrMut},
|
||||
fs::File,
|
||||
header::{
|
||||
errno::{self, EINVAL, EIO, ENOMEM, ENOTDIR},
|
||||
errno::{EINVAL, EIO, ENOMEM, ENOTDIR},
|
||||
fcntl, stdlib, string, sys_stat,
|
||||
unistd::{SEEK_CUR, SEEK_SET},
|
||||
},
|
||||
out::Out,
|
||||
platform::{
|
||||
@@ -52,9 +51,7 @@ impl DIR {
|
||||
}
|
||||
pub fn from_fd(fd: c_int) -> Result<Box<Self>, Errno> {
|
||||
let mut stat = sys_stat::stat::default();
|
||||
unsafe {
|
||||
Sys::fstat(fd, Out::from_mut(&mut stat))?;
|
||||
}
|
||||
Sys::fstat(fd, Out::from_mut(&mut stat))?;
|
||||
if (stat.st_mode & sys_stat::S_IFMT) != sys_stat::S_IFDIR {
|
||||
return Err(Errno(ENOTDIR));
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ pub extern "C" fn __errno_location() -> *mut c_int {
|
||||
/// The `program_invocation_name` variable is a GNU extension.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn __program_invocation_name() -> *mut *mut c_char {
|
||||
unsafe { &raw mut platform::program_invocation_name }
|
||||
&raw mut platform::program_invocation_name
|
||||
}
|
||||
|
||||
/// Get the directory-less name used to invoke the program.
|
||||
@@ -41,7 +41,7 @@ pub unsafe extern "C" fn __program_invocation_name() -> *mut *mut c_char {
|
||||
/// The `program_invocation_short_name` variable is a GNU extension.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn __program_invocation_short_name() -> *mut *mut c_char {
|
||||
unsafe { &raw mut platform::program_invocation_short_name }
|
||||
&raw mut platform::program_invocation_short_name
|
||||
}
|
||||
|
||||
pub const EPERM: c_int = 1; /* Operation not permitted */
|
||||
|
||||
+18
-22
@@ -39,17 +39,15 @@ pub unsafe extern "C" fn strtoimax(
|
||||
endptr: *mut *mut c_char,
|
||||
base: c_int,
|
||||
) -> intmax_t {
|
||||
unsafe {
|
||||
strto_impl!(
|
||||
intmax_t,
|
||||
false,
|
||||
intmax_t::max_value(),
|
||||
intmax_t::min_value(),
|
||||
s,
|
||||
endptr,
|
||||
base
|
||||
)
|
||||
}
|
||||
strto_impl!(
|
||||
intmax_t,
|
||||
false,
|
||||
intmax_t::max_value(),
|
||||
intmax_t::min_value(),
|
||||
s,
|
||||
endptr,
|
||||
base
|
||||
)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoimax.html>.
|
||||
@@ -59,17 +57,15 @@ pub unsafe extern "C" fn strtoumax(
|
||||
endptr: *mut *mut c_char,
|
||||
base: c_int,
|
||||
) -> uintmax_t {
|
||||
unsafe {
|
||||
strto_impl!(
|
||||
uintmax_t,
|
||||
false,
|
||||
uintmax_t::max_value(),
|
||||
uintmax_t::min_value(),
|
||||
s,
|
||||
endptr,
|
||||
base
|
||||
)
|
||||
}
|
||||
strto_impl!(
|
||||
uintmax_t,
|
||||
false,
|
||||
uintmax_t::max_value(),
|
||||
uintmax_t::min_value(),
|
||||
s,
|
||||
endptr,
|
||||
base
|
||||
)
|
||||
}
|
||||
|
||||
// wcstoimax(), wcstoumax() currently defined in header::wchar?
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
use alloc::{
|
||||
boxed::Box,
|
||||
string::{String, ToString},
|
||||
vec::{IntoIter, Vec},
|
||||
};
|
||||
use alloc::{boxed::Box, string::ToString, vec::Vec};
|
||||
use core::mem;
|
||||
|
||||
use crate::{
|
||||
@@ -43,12 +39,10 @@ pub fn lookup_host(host: &str) -> Result<LookupHost, c_int> {
|
||||
|
||||
if let Some(dns_addr) = parse_ipv4_string(&dns_string) {
|
||||
let mut timespec = timespec::default();
|
||||
unsafe {
|
||||
Sys::clock_gettime(
|
||||
time::constants::CLOCK_REALTIME,
|
||||
Out::from_mut(&mut timespec),
|
||||
);
|
||||
}
|
||||
Sys::clock_gettime(
|
||||
time::constants::CLOCK_REALTIME,
|
||||
Out::from_mut(&mut timespec),
|
||||
);
|
||||
let tid = (timespec.tv_nsec >> 16) as u16;
|
||||
|
||||
let packet = Dns {
|
||||
@@ -147,12 +141,10 @@ pub fn lookup_addr(addr: in_addr) -> Result<Vec<Vec<u8>>, c_int> {
|
||||
);
|
||||
|
||||
let mut timespec = timespec::default();
|
||||
unsafe {
|
||||
Sys::clock_gettime(
|
||||
time::constants::CLOCK_REALTIME,
|
||||
Out::from_mut(&mut timespec),
|
||||
)
|
||||
};
|
||||
Sys::clock_gettime(
|
||||
time::constants::CLOCK_REALTIME,
|
||||
Out::from_mut(&mut timespec),
|
||||
);
|
||||
let tid = (timespec.tv_nsec >> 16) as u16;
|
||||
|
||||
let packet = Dns {
|
||||
|
||||
@@ -159,7 +159,7 @@ pub unsafe extern "C" fn pthread_attr_setschedparam(
|
||||
param: *const sched_param,
|
||||
) -> c_int {
|
||||
unsafe {
|
||||
(*attr.cast::<RlctAttr>()).param = unsafe { param.read() };
|
||||
(*attr.cast::<RlctAttr>()).param = param.read();
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ use crate::{
|
||||
self, ERRNO, Pal, Sys, WriteByte,
|
||||
types::{c_char, c_int, c_long, c_uint, c_ulonglong, c_void, off_t, size_t},
|
||||
},
|
||||
sync::Mutex,
|
||||
};
|
||||
|
||||
pub use self::constants::*;
|
||||
@@ -420,7 +419,7 @@ pub unsafe extern "C" fn fflush(stream: *mut FILE) -> c_int {
|
||||
return EOF;
|
||||
}
|
||||
} else {
|
||||
let mut stream = unsafe { unsafe { (*stream).lock() } };
|
||||
let mut stream = unsafe { (*stream).lock() };
|
||||
if stream.flush().is_err() {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
@@ -1102,7 +1102,7 @@ pub unsafe extern "C" fn rand() -> c_int {
|
||||
None => {
|
||||
let mut rng = XorShiftRng::from_seed([1; 16]);
|
||||
let ret = rng_sampler().sample(&mut rng);
|
||||
unsafe { RNG = Some(rng) };
|
||||
RNG = Some(rng);
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,13 @@
|
||||
//
|
||||
// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strptime.html>.
|
||||
|
||||
use crate::{
|
||||
header::{string::strlen, time::tm},
|
||||
platform::types::size_t,
|
||||
};
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use crate::header::time::tm;
|
||||
use alloc::string::String;
|
||||
use core::{
|
||||
ffi::{CStr, c_char, c_int, c_void},
|
||||
mem::MaybeUninit,
|
||||
ptr,
|
||||
ptr::NonNull,
|
||||
slice, str,
|
||||
str,
|
||||
};
|
||||
|
||||
/// For convenience, we define some helper constants for the C-locale.
|
||||
@@ -153,7 +149,7 @@ pub unsafe extern "C" fn strptime(
|
||||
'd' | 'e' => {
|
||||
// parse a 2-digit day (with or without leading zero)
|
||||
let (val, len) = match parse_int(&input_str[index_in_input..], 2, false) {
|
||||
Some(v) => unsafe { v },
|
||||
Some(v) => v,
|
||||
None => return ptr::null_mut(),
|
||||
};
|
||||
unsafe {
|
||||
|
||||
@@ -52,7 +52,7 @@ pub unsafe fn mbrtowc(pwc: *mut wchar_t, s: *const c_char, n: usize, ps: *mut mb
|
||||
}
|
||||
if size == 0 {
|
||||
platform::ERRNO.set(errno::EILSEQ);
|
||||
return unsafe { -1isize as usize };
|
||||
return -1isize as usize;
|
||||
}
|
||||
|
||||
let slice = unsafe { slice::from_raw_parts(s as *const u8, size) };
|
||||
|
||||
@@ -362,18 +362,15 @@ unsafe fn inner_scanf(
|
||||
}
|
||||
}
|
||||
|
||||
let mut ptr: Option<*mut $type> = if ignore {
|
||||
None
|
||||
} else {
|
||||
Some(unsafe { ap.arg() })
|
||||
};
|
||||
let mut ptr: Option<*mut $type> =
|
||||
if ignore { None } else { Some(ap.arg()) };
|
||||
|
||||
while width.map(|w| w > 0).unwrap_or(true)
|
||||
&& !(wc_as_char!(wchar)).is_whitespace()
|
||||
{
|
||||
if let Some(ref mut ptr) = ptr {
|
||||
unsafe { **ptr = wchar as $type };
|
||||
*ptr = unsafe { ptr.offset(1) };
|
||||
**ptr = wchar as $type;
|
||||
*ptr = ptr.offset(1);
|
||||
}
|
||||
width = width.map(|w| w - 1);
|
||||
if width.map(|w| w > 0).unwrap_or(true) && !read!() {
|
||||
|
||||
@@ -481,9 +481,7 @@ pub unsafe extern "C" fn redox_register_scheme_to_ns_v0(
|
||||
Error::mux(
|
||||
redox_rt::sys::register_scheme_to_ns(
|
||||
ns_fd,
|
||||
unsafe {
|
||||
str::from_utf8_unchecked(unsafe { slice::from_raw_parts(name_base, name_len) })
|
||||
},
|
||||
unsafe { str::from_utf8_unchecked(slice::from_raw_parts(name_base, name_len)) },
|
||||
cap_fd,
|
||||
)
|
||||
.map(|()| 0),
|
||||
|
||||
+18
-22
@@ -627,18 +627,16 @@ impl Pal for Sys {
|
||||
fn gettimeofday(mut tp: Out<timeval>, tzp: Option<Out<timezone>>) -> Result<()> {
|
||||
let mut redox_tp = redox_timespec::default();
|
||||
syscall::clock_gettime(syscall::CLOCK_REALTIME, &mut redox_tp)?;
|
||||
unsafe {
|
||||
tp.write(timeval {
|
||||
tv_sec: redox_tp.tv_sec as time_t,
|
||||
tv_usec: (redox_tp.tv_nsec / 1000) as suseconds_t,
|
||||
});
|
||||
tp.write(timeval {
|
||||
tv_sec: redox_tp.tv_sec as time_t,
|
||||
tv_usec: (redox_tp.tv_nsec / 1000) as suseconds_t,
|
||||
});
|
||||
|
||||
if let Some(mut tzp) = tzp {
|
||||
tzp.write(timezone {
|
||||
tz_minuteswest: 0,
|
||||
tz_dsttime: 0,
|
||||
});
|
||||
}
|
||||
if let Some(mut tzp) = tzp {
|
||||
tzp.write(timezone {
|
||||
tz_minuteswest: 0,
|
||||
tz_dsttime: 0,
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1222,7 +1220,7 @@ impl Pal for Sys {
|
||||
|
||||
fn timer_delete(timerid: timer_t) -> Result<()> {
|
||||
unsafe {
|
||||
let timer_st = unsafe { &mut *(timerid as *mut timer_internal_t) };
|
||||
let timer_st = &mut *(timerid as *mut timer_internal_t);
|
||||
let _ = syscall::close(timer_st.timerfd);
|
||||
let _ = syscall::close(timer_st.eventfd);
|
||||
if !timer_st.thread.is_null() {
|
||||
@@ -1391,18 +1389,16 @@ impl Pal for Sys {
|
||||
Ok(())
|
||||
};
|
||||
|
||||
unsafe {
|
||||
read_line(sysname.as_slice_mut().cast_slice_to::<u8>())?;
|
||||
read_line(release.as_slice_mut().cast_slice_to::<u8>())?;
|
||||
read_line(machine.as_slice_mut().cast_slice_to::<u8>())?;
|
||||
read_line(sysname.as_slice_mut().cast_slice_to::<u8>())?;
|
||||
read_line(release.as_slice_mut().cast_slice_to::<u8>())?;
|
||||
read_line(machine.as_slice_mut().cast_slice_to::<u8>())?;
|
||||
|
||||
// Version is not provided
|
||||
version.as_slice_mut().zero();
|
||||
// Version is not provided
|
||||
version.as_slice_mut().zero();
|
||||
|
||||
// Redox doesn't provide domainname in sys:uname
|
||||
//read_line(domainname.as_slice_mut())?;
|
||||
domainname.as_slice_mut().zero();
|
||||
}
|
||||
// Redox doesn't provide domainname in sys:uname
|
||||
//read_line(domainname.as_slice_mut())?;
|
||||
domainname.as_slice_mut().zero();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -270,6 +270,7 @@ fn inner_ptrace(
|
||||
}
|
||||
|
||||
impl PalPtrace for Sys {
|
||||
#[allow(unused_unsafe)] // keeping inner unsafe fails x86_64, removing fails riscv cross-build
|
||||
unsafe fn ptrace(
|
||||
request: c_int,
|
||||
pid: pid_t,
|
||||
|
||||
@@ -1142,7 +1142,7 @@ impl PalSocket for Sys {
|
||||
sv[1] = listener.take() as c_int;
|
||||
Ok(())
|
||||
}
|
||||
_ => unsafe {
|
||||
_ => {
|
||||
todo_skip!(
|
||||
0,
|
||||
"socketpair({}, {}, {}, {:p})",
|
||||
@@ -1152,7 +1152,7 @@ impl PalSocket for Sys {
|
||||
sv.as_mut_ptr()
|
||||
);
|
||||
Err(Errno(EPROTONOSUPPORT))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user