Fix a hard error in clippy
This commit is contained in:
parent
2d16819cbf
commit
bc0d673af0
1 changed files with 1 additions and 11 deletions
|
|
@ -5,17 +5,7 @@ use libdeflater::{CompressionError, CompressionLvl, Compressor};
|
||||||
pub fn deflate(data: &[u8], max_size: &AtomicMin) -> PngResult<Vec<u8>> {
|
pub fn deflate(data: &[u8], max_size: &AtomicMin) -> PngResult<Vec<u8>> {
|
||||||
let mut compressor = Compressor::new(CompressionLvl::best());
|
let mut compressor = Compressor::new(CompressionLvl::best());
|
||||||
let capacity = max_size.get().unwrap_or(data.len() / 2);
|
let capacity = max_size.get().unwrap_or(data.len() / 2);
|
||||||
let mut dest = Vec::with_capacity(capacity);
|
let mut dest = vec![0; capacity];
|
||||||
unsafe {
|
|
||||||
// This is ok because the Vec contains Copy-able data (u8)
|
|
||||||
// and because libdeflater wrapper doesn't try to read
|
|
||||||
// the bytes from the target.
|
|
||||||
//
|
|
||||||
// That said, it should be able to accept MaybeUninit instead,
|
|
||||||
// so I raised an upstream issue that should make this safer:
|
|
||||||
// https://github.com/adamkewley/libdeflater/issues/1
|
|
||||||
dest.set_len(capacity);
|
|
||||||
}
|
|
||||||
let len = compressor
|
let len = compressor
|
||||||
.zlib_compress(data, &mut dest)
|
.zlib_compress(data, &mut dest)
|
||||||
.map_err(|err| match err {
|
.map_err(|err| match err {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue