Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make clippy happy + a few more cleanups #285

Merged
merged 5 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions miniz-sys/miniz.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef unsigned char mz_validate_uint64[sizeof(mz_uint64) == 8 ? 1 : -1];
extern "C" {
#endif

/* ------------------- zlib-style API's */
/* ------------------- zlib-style APIs */
nyurik marked this conversation as resolved.
Show resolved Hide resolved

mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
{
Expand Down Expand Up @@ -6097,8 +6097,8 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
if (!pState->m_zip64)
{
/* Bail early if the archive would obviously become too large */
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size
+ MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + user_extra_data_len +
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size
+ MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + user_extra_data_len +
pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + user_extra_data_central_len
+ MZ_ZIP_DATA_DESCRIPTER_SIZE32) > 0xFFFFFFFF)
{
Expand Down Expand Up @@ -6367,7 +6367,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name,
if (!pState->m_zip64)
{
/* Bail early if the archive would obviously become too large */
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE
+ archive_name_size + comment_size + user_extra_data_len + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + 1024
+ MZ_ZIP_DATA_DESCRIPTER_SIZE32 + user_extra_data_central_len) > 0xFFFFFFFF)
{
Expand Down
16 changes: 8 additions & 8 deletions src/deflate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ mod tests {
let v = crate::random_bytes().take(1024).collect::<Vec<_>>();
for _ in 0..200 {
let to_write = &v[..thread_rng().gen_range(0, v.len())];
real.extend(to_write.iter().map(|x| *x));
real.extend(to_write.iter().copied());
w.write_all(to_write).unwrap();
}
let result = w.finish().unwrap();
let mut r = read::DeflateDecoder::new(&result[..]);
let mut ret = Vec::new();
r.read_to_end(&mut ret).unwrap();
assert!(ret == real);
assert_eq!(ret, real);
}

#[test]
Expand All @@ -37,7 +37,7 @@ mod tests {
let mut r = read::DeflateDecoder::new(&data[..]);
let mut ret = Vec::new();
r.read_to_end(&mut ret).unwrap();
assert!(ret == b"foo");
assert_eq!(ret, b"foo");
}

#[test]
Expand All @@ -47,21 +47,21 @@ mod tests {
let v = crate::random_bytes().take(1024).collect::<Vec<_>>();
for _ in 0..200 {
let to_write = &v[..thread_rng().gen_range(0, v.len())];
real.extend(to_write.iter().map(|x| *x));
real.extend(to_write.iter().copied());
w.write_all(to_write).unwrap();
}
let mut result = w.finish().unwrap();

let result_len = result.len();

for _ in 0..200 {
result.extend(v.iter().map(|x| *x));
result.extend(v.iter().copied());
}

let mut r = read::DeflateDecoder::new(&result[..]);
let mut ret = Vec::new();
r.read_to_end(&mut ret).unwrap();
assert!(ret == real);
assert_eq!(ret, real);
assert_eq!(r.total_in(), result_len as u64);
}

Expand All @@ -84,7 +84,7 @@ mod tests {
);
w.write_all(&v).unwrap();
let w = w.finish().unwrap().finish().unwrap();
assert!(w == v);
assert_eq!(w, v);
}

#[test]
Expand Down Expand Up @@ -159,7 +159,7 @@ mod tests {

let mut d = read::DeflateDecoder::new(&result[..]);
let mut data = Vec::new();
assert!(d.read(&mut data).unwrap() == 0);
assert_eq!(d.read(&mut data).unwrap(), 0);
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions src/ffi/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ impl InflateBackend for Inflate {
let raw = &mut *self.inner.stream_wrapper;
raw.msg = ptr::null_mut();
raw.next_in = input.as_ptr() as *mut u8;
raw.avail_in = cmp::min(input.len(), c_uint::max_value() as usize) as c_uint;
raw.avail_in = cmp::min(input.len(), c_uint::MAX as usize) as c_uint;
raw.next_out = output.as_mut_ptr();
raw.avail_out = cmp::min(output.len(), c_uint::max_value() as usize) as c_uint;
raw.avail_out = cmp::min(output.len(), c_uint::MAX as usize) as c_uint;

let rc = unsafe { mz_inflate(raw, flush as c_int) };

Expand Down Expand Up @@ -325,9 +325,9 @@ impl DeflateBackend for Deflate {
let raw = &mut *self.inner.stream_wrapper;
raw.msg = ptr::null_mut();
raw.next_in = input.as_ptr() as *mut _;
raw.avail_in = cmp::min(input.len(), c_uint::max_value() as usize) as c_uint;
raw.avail_in = cmp::min(input.len(), c_uint::MAX as usize) as c_uint;
raw.next_out = output.as_mut_ptr();
raw.avail_out = cmp::min(output.len(), c_uint::max_value() as usize) as c_uint;
raw.avail_out = cmp::min(output.len(), c_uint::MAX as usize) as c_uint;

let rc = unsafe { mz_deflate(raw, flush as c_int) };

Expand Down
22 changes: 11 additions & 11 deletions src/gz/bufread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn read_gz_header_part<'a, R: Read>(r: &'a mut Buffer<'a, R>) -> io::Result<()>
}

r.part.flg = header[3];
r.part.header.mtime = ((header[4] as u32) << 0)
r.part.header.mtime = (header[4] as u32)
nyurik marked this conversation as resolved.
Show resolved Hide resolved
| ((header[5] as u32) << 8)
| ((header[6] as u32) << 16)
| ((header[7] as u32) << 24);
Expand Down Expand Up @@ -194,12 +194,12 @@ impl<R: BufRead> GzEncoder<R> {
return Ok(0);
}
let crc = self.inner.get_ref().crc();
let ref arr = [
(crc.sum() >> 0) as u8,
nyurik marked this conversation as resolved.
Show resolved Hide resolved
let arr = &[
crc.sum() as u8,
(crc.sum() >> 8) as u8,
(crc.sum() >> 16) as u8,
(crc.sum() >> 24) as u8,
(crc.amount() >> 0) as u8,
crc.amount() as u8,
(crc.amount() >> 8) as u8,
(crc.amount() >> 16) as u8,
(crc.amount() >> 24) as u8,
Expand Down Expand Up @@ -230,11 +230,11 @@ impl<R> GzEncoder<R> {

#[inline]
fn finish(buf: &[u8; 8]) -> (u32, u32) {
let crc = ((buf[0] as u32) << 0)
let crc = (buf[0] as u32)
| ((buf[1] as u32) << 8)
| ((buf[2] as u32) << 16)
| ((buf[3] as u32) << 24);
let amt = ((buf[4] as u32) << 0)
let amt = (buf[4] as u32)
nyurik marked this conversation as resolved.
Show resolved Hide resolved
| ((buf[5] as u32) << 8)
| ((buf[6] as u32) << 16)
| ((buf[7] as u32) << 24);
Expand Down Expand Up @@ -753,20 +753,20 @@ pub mod tests {
}

pub fn set_position(&mut self, pos: u64) {
return self.cursor.set_position(pos);
self.cursor.set_position(pos)
}

pub fn position(&mut self) -> u64 {
return self.cursor.position();
self.cursor.position()
}
}

impl Write for BlockingCursor {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
return self.cursor.write(buf);
self.cursor.write(buf)
}
fn flush(&mut self) -> io::Result<()> {
return self.cursor.flush();
self.cursor.flush()
}
}

Expand All @@ -786,7 +786,7 @@ pub mod tests {
}
Ok(_n) => {}
}
return r;
r
}
}
#[test]
Expand Down
14 changes: 7 additions & 7 deletions src/gz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,23 @@ impl GzBuilder {
let mut header = vec![0u8; 10];
if let Some(v) = extra {
flg |= FEXTRA;
header.push((v.len() >> 0) as u8);
nyurik marked this conversation as resolved.
Show resolved Hide resolved
header.push(v.len() as u8);
header.push((v.len() >> 8) as u8);
header.extend(v);
}
if let Some(filename) = filename {
flg |= FNAME;
header.extend(filename.as_bytes_with_nul().iter().map(|x| *x));
header.extend(filename.as_bytes_with_nul().iter().copied());
}
if let Some(comment) = comment {
flg |= FCOMMENT;
header.extend(comment.as_bytes_with_nul().iter().map(|x| *x));
header.extend(comment.as_bytes_with_nul().iter().copied());
}
header[0] = 0x1f;
header[1] = 0x8b;
header[2] = 8;
header[3] = flg;
header[4] = (mtime >> 0) as u8;
header[4] = mtime as u8;
nyurik marked this conversation as resolved.
Show resolved Hide resolved
header[5] = (mtime >> 8) as u8;
header[6] = (mtime >> 16) as u8;
header[7] = (mtime >> 24) as u8;
Expand Down Expand Up @@ -285,14 +285,14 @@ mod tests {
let v = crate::random_bytes().take(1024).collect::<Vec<_>>();
for _ in 0..200 {
let to_write = &v[..thread_rng().gen_range(0, v.len())];
real.extend(to_write.iter().map(|x| *x));
real.extend(to_write.iter().copied());
w.write_all(to_write).unwrap();
}
let result = w.finish().unwrap();
let mut r = read::GzDecoder::new(&result[..]);
let mut v = Vec::new();
r.read_to_end(&mut v).unwrap();
assert!(v == real);
assert_eq!(v, real);
}

#[test]
Expand All @@ -301,7 +301,7 @@ mod tests {
let mut r = read::GzDecoder::new(read::GzEncoder::new(&v[..], Compression::default()));
let mut res = Vec::new();
r.read_to_end(&mut res).unwrap();
assert!(res == v);
assert_eq!(res, v);
}

#[test]
Expand Down
10 changes: 5 additions & 5 deletions src/gz/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ impl<W: Write> GzEncoder<W> {
while self.crc_bytes_written < 8 {
let (sum, amt) = (self.crc.sum() as u32, self.crc.amount());
let buf = [
(sum >> 0) as u8,
sum as u8,
(sum >> 8) as u8,
(sum >> 16) as u8,
(sum >> 24) as u8,
(amt >> 0) as u8,
amt as u8,
(amt >> 8) as u8,
(amt >> 16) as u8,
(amt >> 24) as u8,
Expand Down Expand Up @@ -304,11 +304,11 @@ impl<W: Write> GzDecoder<W> {
return Err(corrupt());
}

let crc = ((self.crc_bytes[0] as u32) << 0)
let crc = (self.crc_bytes[0] as u32)
| ((self.crc_bytes[1] as u32) << 8)
| ((self.crc_bytes[2] as u32) << 16)
| ((self.crc_bytes[3] as u32) << 24);
let amt = ((self.crc_bytes[4] as u32) << 0)
let amt = (self.crc_bytes[4] as u32)
| ((self.crc_bytes[5] as u32) << 8)
| ((self.crc_bytes[6] as u32) << 16)
| ((self.crc_bytes[7] as u32) << 24);
Expand Down Expand Up @@ -404,7 +404,7 @@ impl<W: AsyncRead + AsyncWrite> AsyncRead for GzDecoder<W> {}
mod tests {
use super::*;

const STR: &'static str = "Hello World Hello World Hello World Hello World Hello World \
const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
Hello World Hello World Hello World Hello World Hello World \
Hello World Hello World Hello World Hello World Hello World \
Hello World Hello World Hello World Hello World Hello World \
Expand Down
16 changes: 6 additions & 10 deletions src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ pub struct Decompress {
inner: Inflate,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
/// Values which indicate the form of flushing to be used when compressing
/// in-memory data.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub enum FlushCompress {
/// A typical parameter for passing to compression/decompression functions,
/// this indicates that the underlying stream to decide how much data to
Expand Down Expand Up @@ -80,14 +81,12 @@ pub enum FlushCompress {
/// The return value may indicate that the stream is not yet done and more
/// data has yet to be processed.
Finish = ffi::MZ_FINISH as isize,

#[doc(hidden)]
_Nonexhaustive,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
/// Values which indicate the form of flushing to be used when
/// decompressing in-memory data.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub enum FlushDecompress {
/// A typical parameter for passing to compression/decompression functions,
/// this indicates that the underlying stream to decide how much data to
Expand All @@ -108,9 +107,6 @@ pub enum FlushDecompress {
/// The return value may indicate that the stream is not yet done and more
/// data has yet to be processed.
Finish = ffi::MZ_FINISH as isize,

#[doc(hidden)]
_Nonexhaustive,
}

/// The inner state for an error when decompressing
Expand Down Expand Up @@ -362,7 +358,7 @@ impl Compress {
unsafe {
let before = self.total_out();
let ret = {
let ptr = output.as_mut_ptr().offset(len as isize);
let ptr = output.as_mut_ptr().add(len);
let out = slice::from_raw_parts_mut(ptr, cap - len);
self.compress(input, out, flush)
};
Expand Down Expand Up @@ -503,7 +499,7 @@ impl Decompress {
unsafe {
let before = self.total_out();
let ret = {
let ptr = output.as_mut_ptr().offset(len as isize);
let ptr = output.as_mut_ptr().add(len);
let out = slice::from_raw_parts_mut(ptr, cap - len);
self.decompress(input, out, flush)
};
Expand Down