Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ include = [
"lib/decompress/huf_decompress_amd64.S",
]

[lints.clippy]
ptr_offset_by_literal = "warn"

[lib]
name = "libzstd_rs_sys"
path = "c2rust-lib.rs"
Expand Down
1 change: 0 additions & 1 deletion c2rust-lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(unused_assignments)]
#![allow(clippy::too_many_arguments)]
#![cfg_attr(all(feature = "nightly", test), feature(test))]
#![cfg_attr(feature = "nightly", feature(likely_unlikely))]
Expand Down
27 changes: 10 additions & 17 deletions lib/common/entropy_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ fn FSE_readNCount_body(

let iend = hbSize;
let mut ip = 0usize;
let mut nbBits: core::ffi::c_int = 0;
let mut remaining: core::ffi::c_int = 0;
let mut threshold: core::ffi::c_int = 0;
let mut bitStream: u32 = 0;
let mut bitCount: core::ffi::c_int = 0;
let mut charnum = 0 as core::ffi::c_uint;
let maxSV1 = (*maxSVPtr).wrapping_add(1);
let mut previous_was_0 = false;
Expand All @@ -45,17 +40,17 @@ fn FSE_readNCount_body(

let read_u32_le = |offset| u32::from_le_bytes(headerBuffer[offset..][..4].try_into().unwrap());

bitStream = read_u32_le(ip);
nbBits = (bitStream & 0xf as core::ffi::c_int as u32).wrapping_add(FSE_MIN_TABLELOG as u32)
as core::ffi::c_int;
let mut bitStream = read_u32_le(ip);
let mut nbBits = (bitStream & 0xf as core::ffi::c_int as u32)
.wrapping_add(FSE_MIN_TABLELOG as u32) as core::ffi::c_int;
if nbBits > FSE_TABLELOG_ABSOLUTE_MAX {
return Err(Error::tableLog_tooLarge);
}
bitStream >>= 4;
bitCount = 4;
let mut bitCount: core::ffi::c_int = 4;
*tableLogPtr = nbBits as core::ffi::c_uint;
remaining = (1 << nbBits) + 1;
threshold = 1 << nbBits;
let mut remaining: core::ffi::c_int = (1 << nbBits) + 1;
let mut threshold: core::ffi::c_int = 1 << nbBits;
nbBits += 1;
loop {
if previous_was_0 {
Expand Down Expand Up @@ -109,7 +104,7 @@ fn FSE_readNCount_body(
}

let max = 2 * threshold - 1 - remaining;
let mut count: core::ffi::c_int = 0;
let mut count: core::ffi::c_int;
if (bitStream & (threshold - 1) as u32) < max as u32 {
count = (bitStream & (threshold - 1) as u32) as core::ffi::c_int;
bitCount += nbBits - 1;
Expand Down Expand Up @@ -267,13 +262,11 @@ fn HUF_readStats_body(
) -> Result<size_t, Error> {
let srcSize = ip.len();

let mut weightTotal: u32 = 0;
let mut iSize: size_t = 0;
let mut oSize: size_t = 0;
if srcSize == 0 {
return Err(Error::srcSize_wrong);
}
iSize = ip[0] as usize;
let mut iSize: size_t = ip[0] as usize;
let oSize: size_t;
if iSize >= 128 {
// Special header case.
oSize = iSize.wrapping_sub(127);
Expand Down Expand Up @@ -308,7 +301,7 @@ fn HUF_readStats_body(

// Collect weight stats.
rankStats[..HUF_TABLELOG_MAX + 1].fill(0);
weightTotal = 0;
let mut weightTotal: u32 = 0;
for weight in huffWeight[..oSize as usize].iter() {
let Some(rank_stat) = rankStats.get_mut(usize::from(*weight)) else {
return Err(Error::corruption_detected);
Expand Down
18 changes: 2 additions & 16 deletions lib/common/fse_decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ use crate::lib::common::{
error_private::Error,
};

#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(C, align(4))]
pub(crate) struct FSE_DTable {
pub header: FSE_DTableHeader,
}

#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(C)]
pub(crate) struct FSE_DecompressWksp {
Expand Down Expand Up @@ -109,7 +103,6 @@ fn FSE_buildDTable_internal(

let largeLimit = ((1) << tableLog.wrapping_sub(1)) as i16;
let mut s: u32 = 0;
s = 0;
while s < maxSV1 {
if normalizedCounter[s as usize] as core::ffi::c_int == -(1) {
let fresh0 = highThreshold;
Expand Down Expand Up @@ -137,10 +130,9 @@ fn FSE_buildDTable_internal(
let mut sv = 0u64;

for s_0 in 0..maxSV1 {
let mut i: core::ffi::c_int = 0;
let n = normalizedCounter[s_0 as usize] as core::ffi::c_int;
spread[pos as usize..][..8].copy_from_slice(&sv.to_le_bytes());
i = 8;
let mut i: core::ffi::c_int = 8;
while i < n {
spread[pos as usize..][i as usize..][..8].copy_from_slice(&sv.to_le_bytes());
i += 8;
Expand All @@ -152,10 +144,8 @@ fn FSE_buildDTable_internal(
let mut position = 0 as size_t;
let mut s_1: size_t = 0;
let unroll = 2;
s_1 = 0;
while s_1 < tableSize as size_t {
let mut u: size_t = 0;
u = 0;
while u < unroll {
let uPosition = position.wrapping_add(u * step) & tableMask;
elements[uPosition as usize].symbol = spread[(s_1 + u) as usize];
Expand Down Expand Up @@ -325,7 +315,7 @@ fn FSE_decompress_wksp_body(
workspace: &mut Workspace,
bmi2: core::ffi::c_int,
) -> Result<size_t, Error> {
let mut wkspSize = size_of::<Workspace>();
let wkspSize = size_of::<Workspace>();

let mut tableLog: core::ffi::c_uint = 0;
let mut maxSymbolValue = FSE_MAX_SYMBOL_VALUE as core::ffi::c_uint;
Expand Down Expand Up @@ -371,10 +361,6 @@ fn FSE_decompress_wksp_body(
{
return Err(Error::tableLog_tooLarge);
}
wkspSize = wkspSize.wrapping_sub(
size_of::<FSE_DecompressWksp>()
.wrapping_add((1usize + (1 << tableLog)).wrapping_mul(size_of::<FSE_DTable>())),
);

let () = FSE_buildDTable_internal(
&mut workspace.dtable,
Expand Down
3 changes: 1 addition & 2 deletions lib/common/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ pub(crate) unsafe fn POOL_create_advanced(
queueSize: size_t,
customMem: ZSTD_customMem,
) -> *mut POOL_ctx {
let mut ctx = core::ptr::null_mut::<POOL_ctx>();
if numThreads == 0 {
return core::ptr::null_mut();
}
ctx = ZSTD_customCalloc(size_of::<POOL_ctx>(), customMem) as *mut POOL_ctx;
let ctx = ZSTD_customCalloc(size_of::<POOL_ctx>(), customMem) as *mut POOL_ctx;
if ctx.is_null() {
return core::ptr::null_mut();
}
Expand Down
27 changes: 6 additions & 21 deletions lib/compress/fse_compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ pub(crate) unsafe fn FSE_buildCTable_wksp(
}
*tableU16.sub(2) = tableLog as u16;
*tableU16.sub(1) = maxSymbolValue as u16;
let mut u: u32 = 0;
*cumul = 0;
u = 1;
let mut u: u32 = 1;
while u <= maxSV1 {
if *normalizedCounter.offset(u.wrapping_sub(1) as isize) as core::ffi::c_int == -(1) {
*cumul.offset(u as isize) =
Expand All @@ -115,12 +114,10 @@ pub(crate) unsafe fn FSE_buildCTable_wksp(
let mut pos = 0 as size_t;
let mut sv = 0u64;
let mut s: u32 = 0;
s = 0;
while s < maxSV1 {
let mut i: core::ffi::c_int = 0;
let n = *normalizedCounter.offset(s as isize) as core::ffi::c_int;
MEM_write64(spread.add(pos) as *mut core::ffi::c_void, sv);
i = 8;
let mut i: core::ffi::c_int = 8;
while i < n {
MEM_write64(
spread.add(pos).offset(i as isize) as *mut core::ffi::c_void,
Expand All @@ -135,10 +132,8 @@ pub(crate) unsafe fn FSE_buildCTable_wksp(
let mut position = 0 as size_t;
let mut s_0: size_t = 0;
let unroll = 2;
s_0 = 0;
while s_0 < tableSize as size_t {
let mut u_0: size_t = 0;
u_0 = 0;
while u_0 < unroll {
let uPosition = position.wrapping_add(u_0 * step as size_t) & tableMask as size_t;
*tableSymbol.add(uPosition) = *spread.add(s_0.wrapping_add(u_0));
Expand All @@ -150,11 +145,9 @@ pub(crate) unsafe fn FSE_buildCTable_wksp(
} else {
let mut position_0 = 0u32;
let mut symbol: u32 = 0;
symbol = 0;
while symbol < maxSV1 {
let mut nbOccurrences: core::ffi::c_int = 0;
let freq = *normalizedCounter.offset(symbol as isize) as core::ffi::c_int;
nbOccurrences = 0;
while nbOccurrences < freq {
*tableSymbol.offset(position_0 as isize) = symbol as u8;
position_0 = position_0.wrapping_add(step) & tableMask;
Expand All @@ -167,7 +160,6 @@ pub(crate) unsafe fn FSE_buildCTable_wksp(
}
}
let mut u_1: u32 = 0;
u_1 = 0;
while u_1 < tableSize {
let s_1 = *tableSymbol.offset(u_1 as isize);
let fresh1 = &mut (*cumul.offset(s_1 as isize));
Expand All @@ -178,7 +170,6 @@ pub(crate) unsafe fn FSE_buildCTable_wksp(
}
let mut total = 0 as core::ffi::c_uint;
let mut s_2: core::ffi::c_uint = 0;
s_2 = 0;
while s_2 <= maxSymbolValue {
match *normalizedCounter.offset(s_2 as isize) as core::ffi::c_int {
0 => {
Expand Down Expand Up @@ -239,10 +230,7 @@ unsafe fn FSE_writeNCount_generic(
let ostart = header as *mut u8;
let mut out = ostart;
let oend = ostart.add(headerBufferSize);
let mut nbBits: core::ffi::c_int = 0;
let tableSize = (1) << tableLog;
let mut remaining: core::ffi::c_int = 0;
let mut threshold: core::ffi::c_int = 0;
let mut bitStream = 0;
let mut bitCount = 0;
let mut symbol = 0;
Expand All @@ -251,9 +239,9 @@ unsafe fn FSE_writeNCount_generic(
bitStream = (bitStream as core::ffi::c_uint)
.wrapping_add(tableLog.wrapping_sub(FSE_MIN_TABLELOG as core::ffi::c_uint) << bitCount);
bitCount += 4;
remaining = tableSize + 1;
threshold = tableSize;
nbBits = tableLog as core::ffi::c_int + 1;
let mut remaining = tableSize + 1;
let mut threshold = tableSize;
let mut nbBits = tableLog as core::ffi::c_int + 1;
while symbol < alphabetSize && remaining > 1 {
if previousIs0 != 0 {
let mut start = symbol;
Expand Down Expand Up @@ -421,10 +409,8 @@ unsafe fn FSE_normalizeM2(
let NOT_YET_ASSIGNED = -(2) as core::ffi::c_short;
let mut s: u32 = 0;
let mut distributed = 0u32;
let mut ToDistribute: u32 = 0;
let lowThreshold = (total >> tableLog) as u32;
let mut lowOne = ((total * 3) >> tableLog.wrapping_add(1)) as u32;
s = 0;
while s <= maxSymbolValue {
if *count.offset(s as isize) == 0 {
*norm.offset(s as isize) = 0;
Expand All @@ -441,7 +427,7 @@ unsafe fn FSE_normalizeM2(
}
s = s.wrapping_add(1);
}
ToDistribute = ((1 << tableLog) as u32).wrapping_sub(distributed);
let mut ToDistribute = ((1 << tableLog) as u32).wrapping_sub(distributed);
if ToDistribute == 0 {
return 0;
}
Expand Down Expand Up @@ -540,7 +526,6 @@ pub(crate) unsafe fn FSE_normalizeCount(
let mut largest = 0;
let mut largestP = 0;
let lowThreshold = (total >> tableLog) as u32;
s = 0;
while s <= maxSymbolValue {
if *count.offset(s as isize) as size_t == total {
return 0;
Expand Down
2 changes: 0 additions & 2 deletions lib/compress/hist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ pub unsafe fn HIST_count_simple(
}
*maxSymbolValuePtr = maxSymbolValue;
let mut s: u32 = 0;
s = 0;
while s <= maxSymbolValue {
if *count.offset(s as isize) > largestCount {
largestCount = *count.offset(s as isize);
Expand Down Expand Up @@ -154,7 +153,6 @@ unsafe fn HIST_count_parallel_wksp(
*fresh21 = (*fresh21).wrapping_add(1);
}
let mut s: u32 = 0;
s = 0;
while s < 256 {
let fresh22 = &mut (*Counting1.offset(s as isize));
*fresh22 = (*fresh22).wrapping_add(
Expand Down
Loading
Loading