Verified Commit bce2f47f authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Fix more clippy warnings

parent 128d4609
......@@ -47,7 +47,7 @@ pub unsafe extern "C" fn getopt_long(
|| *current_arg.offset(1) == 0
{
-1
} else if string::strcmp(current_arg, b"--\0".as_ptr() as _) == 0 {
} else if string::strcmp(current_arg, c_str!("--").as_ptr()) == 0 {
optind += 1;
-1
} else {
......
......@@ -219,7 +219,7 @@ pub extern "C" fn getpwnam(name: *const c_char) -> *mut passwd {
// /etc/passwd should not contain any NUL bytes in the middle
// of entries, but if this happens, it can't possibly match the
// search query since it's NUL terminated.
if *c == 0 || unsafe { *name.offset(i as isize) } != *c as c_char {
if *c == 0 || unsafe { *name.add(i) } != *c as c_char {
return false;
}
}
......
......@@ -128,9 +128,9 @@ pub unsafe extern "C" fn regexec(
if !matches.is_empty() && eflags & REG_NOSUB != REG_NOSUB && !pmatch.is_null() && nmatch > 0 {
let first = &matches[0];
for i in 0..nmatch as usize {
for i in 0..nmatch {
let (start, end) = first.get(i).and_then(|&range| range).unwrap_or((!0, !0));
*pmatch.offset(i as isize) = regmatch_t {
*pmatch.add(i) = regmatch_t {
rm_so: start,
rm_eo: end,
};
......
......@@ -317,7 +317,7 @@ pub unsafe extern "C" fn fgets(original: *mut c_char, max: c_int, stream: *mut F
stream.consume(read);
out = out.offset(read as isize);
out = out.add(read);
left -= read;
if exit {
......@@ -850,7 +850,7 @@ pub extern "C" fn tempnam(_dir: *const c_char, _pfx: *const c_char) -> *mut c_ch
#[no_mangle]
pub unsafe extern "C" fn tmpfile() -> *mut FILE {
let mut file_name = *b"/tmp/tmpfileXXXXXX";
let mut file_name = *b"/tmp/tmpfileXXXXXX\0";
let file_name = file_name.as_mut_ptr() as *mut c_char;
let fd = stdlib::mkstemp(file_name);
......@@ -858,7 +858,7 @@ pub unsafe extern "C" fn tmpfile() -> *mut FILE {
return ptr::null_mut();
}
let fp = fdopen(fd, b"w+".as_ptr() as *const i8);
let fp = fdopen(fd, c_str!("w+").as_ptr());
{
let file_name = CStr::from_ptr(file_name);
Sys::unlink(file_name);
......
......@@ -349,7 +349,7 @@ unsafe fn inner_scanf<R: Read>(
for i in 0..width.unwrap_or(1) {
if let Some(ptr) = ptr {
*ptr.offset(i as isize) = byte as c_char;
*ptr.add(i) = byte as c_char;
}
width = width.map(|w| w - 1);
if width.map(|w| w > 0).unwrap_or(true) && !read!() {
......
......@@ -267,7 +267,7 @@ pub extern "C" fn gcvt(value: c_double, ndigit: c_int, buf: *mut c_char) -> *mut
unsafe fn find_env(search: *const c_char) -> Option<(usize, *mut c_char)> {
for (i, item) in platform::inner_environ.iter().enumerate() {
let mut item = *item;
if item == ptr::null_mut() {
if item.is_null() {
assert_eq!(
i,
platform::inner_environ.len() - 1,
......
......@@ -26,7 +26,7 @@ pub unsafe extern "C" fn memccpy(
if memcpy(dest, src, dist).is_null() {
return ptr::null_mut();
}
(dest as *mut u8).offset(dist as isize + 1) as *mut c_void
(dest as *mut u8).add(dist + 1) as *mut c_void
}
#[no_mangle]
......@@ -79,8 +79,8 @@ pub unsafe extern "C" fn memcmp(s1: *const c_void, s2: *const c_void, n: size_t)
for _ in 0..div {
if *a != *b {
for i in 0..mem::size_of::<usize>() {
let c = *(a as *const u8).offset(i as isize);
let d = *(b as *const u8).offset(i as isize);
let c = *(a as *const u8).add(i);
let d = *(b as *const u8).add(i);
if c != d {
return c as c_int - d as c_int;
}
......@@ -107,11 +107,11 @@ pub unsafe extern "C" fn memcmp(s1: *const c_void, s2: *const c_void, n: size_t)
pub unsafe extern "C" fn memcpy(s1: *mut c_void, s2: *const c_void, n: size_t) -> *mut c_void {
let mut i = 0;
while i + 7 < n {
*(s1.offset(i as isize) as *mut u64) = *(s2.offset(i as isize) as *const u64);
*(s1.add(i) as *mut u64) = *(s2.add(i) as *const u64);
i += 8;
}
while i < n {
*(s1 as *mut u8).offset(i as isize) = *(s2 as *const u8).offset(i as isize);
*(s1 as *mut u8).add(i) = *(s2 as *const u8).add(i);
i += 1;
}
s1
......@@ -124,13 +124,13 @@ pub unsafe extern "C" fn memmove(s1: *mut c_void, s2: *const c_void, n: size_t)
let mut i = n;
while i != 0 {
i -= 1;
*(s1 as *mut u8).offset(i as isize) = *(s2 as *const u8).offset(i as isize);
*(s1 as *mut u8).add(i) = *(s2 as *const u8).add(i);
}
} else {
// copy from beginning
let mut i = 0;
while i < n {
*(s1 as *mut u8).offset(i as isize) = *(s2 as *const u8).offset(i as isize);
*(s1 as *mut u8).add(i) = *(s2 as *const u8).add(i);
i += 1;
}
}
......@@ -141,7 +141,7 @@ pub unsafe extern "C" fn memmove(s1: *mut c_void, s2: *const c_void, n: size_t)
pub unsafe extern "C" fn memset(s: *mut c_void, c: c_int, n: size_t) -> *mut c_void {
let mut i = 0;
while i < n {
*(s as *mut u8).offset(i as isize) = c as u8;
*(s as *mut u8).add(i) = c as u8;
i += 1;
}
s
......@@ -235,10 +235,12 @@ pub unsafe extern "C" fn strndup(s1: *const c_char, size: size_t) -> *mut c_char
platform::errno = ENOMEM as c_int;
} else {
//memcpy(buffer, s1, len)
for i in 0..len as isize {
*buffer.offset(i) = *s1.offset(i);
let mut i = 0;
while i < len {
*buffer.add(i) = *s1.add(i);
i += 1;
}
*buffer.offset(len as isize) = 0;
*buffer.add(len) = 0;
}
buffer
......@@ -270,7 +272,7 @@ pub unsafe extern "C" fn strlen(s: *const c_char) -> size_t {
pub unsafe extern "C" fn strnlen(s: *const c_char, size: size_t) -> size_t {
let mut i = 0;
while i < size {
if *s.offset(i as isize) == 0 {
if *s.add(i) == 0 {
break;
}
i += 1;
......@@ -288,15 +290,15 @@ pub unsafe extern "C" fn strncat(s1: *mut c_char, s2: *const c_char, n: size_t)
let len = strlen(s1 as *const c_char);
let mut i = 0;
while i < n {
let b = *s2.offset(i as isize);
let b = *s2.add(i);
if b == 0 {
break;
}
*s1.offset((len + i) as isize) = b;
*s1.add(len + i) = b;
i += 1;
}
*s1.offset((len + i) as isize) = 0;
*s1.add(len + i) = 0;
s1
}
......@@ -334,7 +336,7 @@ pub unsafe extern "C" fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t
#[no_mangle]
pub unsafe extern "C" fn strpbrk(s1: *const c_char, s2: *const c_char) -> *mut c_char {
let p = s1.offset(strcspn(s1, s2) as isize);
let p = s1.add(strcspn(s1, s2));
if *p != 0 {
p as *mut c_char
} else {
......
......@@ -21,7 +21,7 @@ pub unsafe extern "C" fn brk(addr: *mut c_void) -> c_int {
#[no_mangle]
pub unsafe extern "C" fn sbrk(incr: intptr_t) -> *mut c_void {
if BRK == ptr::null_mut() {
if BRK.is_null() {
BRK = Sys::brk(ptr::null_mut());
}
......
......@@ -233,7 +233,7 @@ pub extern "C" fn getcwd(mut buf: *mut c_char, mut size: size_t) -> *mut c_char
}
let ret = Sys::getcwd(buf, size);
if ret == ptr::null_mut() {
if ret.is_null() {
return ptr::null_mut();
}
......@@ -246,7 +246,7 @@ pub extern "C" fn getcwd(mut buf: *mut c_char, mut size: size_t) -> *mut c_char
let heap_buf = unsafe { platform::alloc(len) as *mut c_char };
for i in 0..len {
unsafe {
*heap_buf.offset(i as isize) = stack_buf[i];
*heap_buf.add(i) = stack_buf[i];
}
}
heap_buf
......
......@@ -135,14 +135,14 @@ pub unsafe extern "C" fn mbsnrtowcs(
let mut wc: wchar_t = 0;
let amount = mbrtowc(
&mut wc,
src.offset(src_offset as isize),
src.add(src_offset),
src_len - src_offset,
ps,
);
// Stop in the event a decoding error occured.
if amount == -1isize as usize {
*src_ptr = src.offset(src_offset as isize);
*src_ptr = src.add(src_offset);
return 1isize as usize;
}
......@@ -154,7 +154,7 @@ pub unsafe extern "C" fn mbsnrtowcs(
// Store the decoded wide character in the destination buffer.
if !dst_ptr.is_null() {
*dst_ptr.offset(dst_offset as isize) = wc;
*dst_ptr.add(dst_offset) = wc;
}
// Stop decoding after decoding a null character and return a NULL
......@@ -170,7 +170,7 @@ pub unsafe extern "C" fn mbsnrtowcs(
src_offset += amount;
}
*src_ptr = src.offset(src_offset as isize);
*src_ptr = src.add(src_offset);
dst_offset
}
......@@ -249,13 +249,11 @@ pub extern "C" fn vswprintf(
#[no_mangle]
pub unsafe extern "C" fn wcrtomb(s: *mut c_char, wc: wchar_t, ps: *mut mbstate_t) -> size_t {
let mut buffer: [c_char; MB_CUR_MAX as usize] = [0; MB_CUR_MAX as usize];
let mut wc_cpy = wc;
let mut s_cpy = s;
if s.is_null() {
wc_cpy = 0;
s_cpy = buffer.as_mut_ptr();
}
let (s_cpy, wc_cpy) = if s.is_null() {
(buffer.as_mut_ptr(), 0)
} else {
(s, wc)
};
utf8::wcrtomb(s_cpy, wc_cpy, ps)
}
......
......@@ -103,7 +103,7 @@ impl Write for StringWriter {
ptr::copy_nonoverlapping(buf.as_ptr(), self.0, copy_size);
self.1 -= copy_size;
self.0 = self.0.offset(copy_size as isize);
self.0 = self.0.add(copy_size);
*self.0 = 0;
}
......@@ -136,8 +136,8 @@ impl Write for UnsafeStringWriter {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
unsafe {
ptr::copy_nonoverlapping(buf.as_ptr(), self.0, buf.len());
*self.0.offset(buf.len() as isize) = b'\0';
self.0 = self.0.offset(buf.len() as isize);
self.0 = self.0.add(buf.len());
*self.0 = b'\0';
}
Ok(buf.len())
}
......
......@@ -43,20 +43,20 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
let envp = sp.envp();
let mut len = 0;
while *envp.offset(len) != ptr::null() {
while ! (*envp.add(len)).is_null() {
len += 1;
}
platform::inner_environ = Vec::with_capacity(len as usize + 1);
platform::inner_environ = Vec::with_capacity(len + 1);
for i in 0..len {
let mut item = *envp.offset(i);
let mut item = *envp.add(i);
let mut len = 0;
while *item.offset(len) != 0 {
while *item.add(len) != 0 {
len += 1;
}
let buf = platform::alloc(len as usize + 1) as *mut c_char;
let buf = platform::alloc(len + 1) as *mut c_char;
for i in 0..=len {
*buf.offset(i) = *item.offset(i);
*buf.add(i) = *item.add(i);
}
platform::inner_environ.push(buf);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment