Fix Clippy warnings

This commit is contained in:
Mateusz Mikuła
2019-05-10 12:01:02 +02:00
parent 30f6a9c323
commit 7597c082e7
20 changed files with 115 additions and 126 deletions
+1 -1
View File
@@ -92,7 +92,7 @@ pub unsafe extern "C" fn gethostent() -> *mut hostent {
let mut _host_aliases: Vec<Vec<u8>> = Vec::new();
while let Some(s) = iter.next() {
for s in iter {
let mut alias = s.as_bytes().to_vec();
alias.push(b'\0');
_host_aliases.push(alias);
+1 -1
View File
@@ -32,7 +32,7 @@ pub fn lookup_host(host: &str) -> Result<LookupHost, c_int> {
let dns_vec: Vec<u8> = dns_string
.trim()
.split(".")
.split('.')
.map(|octet| octet.parse::<u8>().unwrap_or(0))
.collect();
+2 -2
View File
@@ -219,7 +219,7 @@ pub unsafe extern "C" fn gethostbyaddr(
Ok(s) => {
_HOST_ADDR_LIST = mem::transmute::<u32, [u8; 4]>(addr.s_addr);
HOST_ADDR_LIST = [_HOST_ADDR_LIST.as_mut_ptr() as *mut c_char, ptr::null_mut()];
let mut host_name = s[0].to_vec();
let host_name = s[0].to_vec();
HOST_NAME = Some(host_name);
HOST_ENTRY = hostent {
h_name: HOST_NAME.as_mut().unwrap().as_mut_ptr() as *mut c_char,
@@ -431,7 +431,7 @@ pub unsafe extern "C" fn getprotoent() -> *mut protoent {
PROTO_NUM = Some(atoi(num.as_mut_slice().as_mut_ptr() as *mut i8));
let mut _proto_aliases: Vec<Vec<u8>> = Vec::new();
while let Some(s) = iter.next() {
for s in iter {
let mut alias = s.as_bytes().to_vec();
alias.push(b'\0');
_proto_aliases.push(alias);
+1 -1
View File
@@ -72,7 +72,7 @@ where
};
// Parse into passwd
let mut parts: [&[u8]; 7] = sys::split(&line);
let parts: [&[u8]; 7] = sys::split(&line);
if !callback(&parts) {
continue;
+1 -1
View File
@@ -31,7 +31,7 @@ pub const L_tmpnam: c_int = 7;
pub const TMP_MAX: int32_t = 2_147_483_647;
// XXX: defined manually in bits/stdio.h as well because cbindgen can't handle
// string constants in any form AFAICT
pub const P_tmpdir: &'static [u8; 5] = b"/tmp\0";
pub const P_tmpdir: &[u8; 5] = b"/tmp\0";
#[allow(non_camel_case_types)]
pub type fpos_t = off_t;
+5 -5
View File
@@ -319,7 +319,7 @@ pub unsafe extern "C" fn fgets(
// TODO: When NLL is a thing, this block can be flattened out
let (read, exit) = {
let mut buf = match stream.fill_buf() {
let buf = match stream.fill_buf() {
Ok(buf) => buf,
Err(_) => return ptr::null_mut(),
};
@@ -580,7 +580,7 @@ pub unsafe extern "C" fn fwrite(
let buf = slice::from_raw_parts_mut(ptr as *mut u8, size as usize * nitems as usize);
let mut written = 0;
while written < buf.len() {
match stream.write(&mut buf[written..]) {
match stream.write(&buf[written..]) {
Ok(0) | Err(_) => break,
Ok(n) => written += n,
}
@@ -885,8 +885,8 @@ pub unsafe extern "C" fn tempnam(dir: *const c_char, pfx: *const c_char) -> *mut
let dirname = {
let tmpdir = stdlib::getenv(b"TMPDIR\0".as_ptr() as _);
[tmpdir, dir, P_tmpdir.as_ptr() as _]
.into_iter()
.map(|&d| d)
.iter()
.copied()
.skip_while(|&d| !is_appropriate(d))
.next()
.unwrap_or(b"/tmp\0".as_ptr() as _)
@@ -934,7 +934,7 @@ pub unsafe extern "C" fn tmpfile() -> *mut FILE {
Sys::unlink(file_name);
}
if fp == ptr::null_mut() {
if fp.is_null() {
Sys::close(fd);
}
+23 -22
View File
@@ -307,7 +307,7 @@ fn float_string(float: c_double, precision: usize, trim: bool) -> String {
let mut string = format!("{:.p$}", float, p = precision);
if trim {
let truncate = {
let mut slice = string.trim_end_matches('0');
let slice = string.trim_end_matches('0');
if slice.ends_with('.') {
slice.len() - 1
} else {
@@ -678,22 +678,23 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
// add an extra zero if octal.
let no_precision = precision.map(|pad| pad < string.len()).unwrap_or(true);
let mut len = string.len();
let mut final_len = string.len().max(precision.unwrap_or(0))
+ if alternate && string != "0" {
match fmt {
b'o' if no_precision => 1,
b'x' | b'X' => 2,
_ => 0,
}
} else {
0
};
if zero {
let len;
let final_len = if zero {
len = 0;
final_len = 0;
}
0
} else {
len = string.len();
len.max(precision.unwrap_or(0))
+ if alternate && string != "0" {
match fmt {
b'o' if no_precision => 1,
b'x' | b'X' => 2,
_ => 0,
}
} else {
0
}
};
pad(w, !left, b' ', final_len..pad_space)?;
@@ -714,7 +715,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
pad(w, left, b' ', final_len..pad_space)?;
}
FmtKind::Scientific => {
let mut float = match varargs.get(index, &mut ap, Some(&arg)) {
let float = match varargs.get(index, &mut ap, Some(&arg)) {
VaArg::c_double(i) => i,
_ => panic!("this should not be possible"),
};
@@ -725,7 +726,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
)?;
}
FmtKind::Decimal => {
let mut float = match varargs.get(index, &mut ap, Some(&arg)) {
let float = match varargs.get(index, &mut ap, Some(&arg)) {
VaArg::c_double(i) => i,
_ => panic!("this should not be possible"),
};
@@ -734,7 +735,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
fmt_float_normal(w, false, precision, float, left, pad_space, pad_zero)?;
}
FmtKind::AnyNotation => {
let mut float = match varargs.get(index, &mut ap, Some(&arg)) {
let float = match varargs.get(index, &mut ap, Some(&arg)) {
VaArg::c_double(i) => i,
_ => panic!("this should not be possible"),
};
@@ -758,7 +759,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
FmtKind::String => {
// if intkind == IntKind::Long || intkind == IntKind::LongLong, handle *const wchar_t
let mut ptr = match varargs.get(index, &mut ap, Some(&arg)) {
let ptr = match varargs.get(index, &mut ap, Some(&arg)) {
VaArg::pointer(p) => p,
_ => panic!("this should not be possible"),
} as *const c_char;
@@ -790,7 +791,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
pad(w, left, b' ', 1..pad_space)?;
}
FmtKind::Pointer => {
let mut ptr = match varargs.get(index, &mut ap, Some(&arg)) {
let ptr = match varargs.get(index, &mut ap, Some(&arg)) {
VaArg::pointer(p) => p,
_ => panic!("this should not be possible"),
};
@@ -815,7 +816,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
pad(w, left, b' ', len..pad_space)?;
}
FmtKind::GetWritten => {
let mut ptr = match varargs.get(index, &mut ap, Some(&arg)) {
let ptr = match varargs.get(index, &mut ap, Some(&arg)) {
VaArg::pointer(p) => p,
_ => panic!("this should not be possible"),
};
+6 -5
View File
@@ -349,7 +349,7 @@ unsafe fn inner_scanf<R: Read>(
}
}
b'c' => {
let mut ptr: Option<*mut c_char> = if ignore { None } else { Some(ap.arg()) };
let ptr: Option<*mut c_char> = if ignore { None } else { Some(ap.arg()) };
for i in 0..width.unwrap_or(1) {
if let Some(ptr) = ptr {
@@ -370,11 +370,12 @@ unsafe fn inner_scanf<R: Read>(
c = next_byte(&mut format)?;
let mut matches = Vec::new();
let mut invert = false;
if c == b'^' {
let invert = if c == b'^' {
c = next_byte(&mut format)?;
invert = true;
}
true
} else {
false
};
let mut prev;
loop {
+2 -1
View File
@@ -265,6 +265,7 @@ pub unsafe extern "C" fn exit(status: c_int) {
// Look for the neighbor functions in memory until the end
let mut f = &__fini_array_end as *const _;
#[allow(clippy::op_ref)]
while f > &__fini_array_start {
f = f.offset(-1);
(*f)();
@@ -846,7 +847,7 @@ pub unsafe fn convert_hex(s: *const c_char) -> Option<(c_ulong, isize, bool)> {
pub unsafe fn convert_integer(s: *const c_char, base: c_int) -> Option<(c_ulong, isize, bool)> {
// -1 means the character is invalid
#[cfg_attr(rustfmt, rustfmt_skip)]
#[rustfmt::skip]
const LOOKUP_TABLE: [c_long; 256] = [
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+1 -1
View File
@@ -107,7 +107,7 @@ fn heapify(
// we start at the last parent in the heap (the parent of the last child)
let last_parent = (nel - 2) / 2;
for start in (0..last_parent + 1).rev() {
for start in (0..=last_parent).rev() {
heap_sift_down(base, start, nel - 1, width, comp);
}
}
+3 -3
View File
@@ -74,7 +74,7 @@ pub fn select_epoll(
if fd_set.isset(fd) {
let mut event = epoll_event {
events: EPOLLIN,
data: epoll_data { fd: fd },
data: epoll_data { fd },
..Default::default()
};
if epoll_ctl(*ep, EPOLL_CTL_ADD, fd, &mut event) < 0 {
@@ -92,7 +92,7 @@ pub fn select_epoll(
if fd_set.isset(fd) {
let mut event = epoll_event {
events: EPOLLOUT,
data: epoll_data { fd: fd },
data: epoll_data { fd },
..Default::default()
};
if epoll_ctl(*ep, EPOLL_CTL_ADD, fd, &mut event) < 0 {
@@ -110,7 +110,7 @@ pub fn select_epoll(
if fd_set.isset(fd) {
let mut event = epoll_event {
events: EPOLLERR,
data: epoll_data { fd: fd },
data: epoll_data { fd },
..Default::default()
};
if epoll_ctl(*ep, EPOLL_CTL_ADD, fd, &mut event) < 0 {
+1 -1
View File
@@ -176,7 +176,7 @@ pub unsafe extern "C" fn execvp(file: *const c_char, argv: *const *mut c_char) -
let path_env = getenv(c_str!("PATH\0").as_ptr());
if !path_env.is_null() {
let path_env = CStr::from_ptr(path_env);
for mut path in path_env.to_bytes().split(|&b| b == PATH_SEPARATOR) {
for path in path_env.to_bytes().split(|&b| b == PATH_SEPARATOR) {
let mut program = path.to_vec();
program.push(b'/');
program.extend_from_slice(file.to_bytes());
+2 -2
View File
@@ -301,7 +301,7 @@ pub unsafe extern "C" fn wcschr(ws: *const wchar_t, wc: wchar_t) -> *mut wchar_t
if *ws.add(i) == wc {
return ws.add(i) as *mut wchar_t;
} else if *ws.add(i) == 0 {
return 0 as *mut wchar_t;
return ptr::null_mut();
}
i += 1;
}
@@ -523,7 +523,7 @@ pub unsafe extern "C" fn wmemchr(ws: *const wchar_t, wc: wchar_t, n: size_t) ->
return ws.add(i) as *mut wchar_t;
}
}
0 as *mut wchar_t
ptr::null_mut()
}
#[no_mangle]