Skip to content

Commit 51d4f49

Browse files
committed
fn ZDICT_flatLit: make safe
1 parent 3906454 commit 51d4f49

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

lib/dictBuilder/zdict.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -851,17 +851,15 @@ unsafe fn ZDICT_insertSortCount(table: *mut offsetCount_t, val: u32, count: u32)
851851
u = u.wrapping_sub(1);
852852
}
853853
}
854-
unsafe fn ZDICT_flatLit(countLit: *mut core::ffi::c_uint) {
855-
let mut u: core::ffi::c_int = 0;
856-
u = 1;
857-
while u < 256 {
858-
*countLit.offset(u as isize) = 2;
859-
u += 1;
860-
}
861-
*countLit = 4;
862-
*countLit.add(253) = 1;
863-
*countLit.add(254) = 1;
854+
855+
fn ZDICT_flatLit(countLit: &mut [core::ffi::c_uint; 256]) {
856+
countLit.fill(2);
857+
858+
countLit[0] = 4;
859+
countLit[253] = 1;
860+
countLit[254] = 1;
864861
}
862+
865863
const OFFCODE_MAX: core::ffi::c_int = 30;
866864
unsafe fn ZDICT_analyzeEntropy(
867865
dstBuffer: *mut core::ffi::c_void,
@@ -1020,7 +1018,7 @@ unsafe fn ZDICT_analyzeEntropy(
10201018
"warning : pathological dataset : literals are not compressible : samples are noisy or too regular "
10211019
);
10221020
}
1023-
ZDICT_flatLit(countLit.as_mut_ptr());
1021+
ZDICT_flatLit(&mut countLit);
10241022
maxNbBits = HUF_buildCTable_wksp(
10251023
hufTable.as_mut_ptr(),
10261024
countLit.as_mut_ptr(),

0 commit comments

Comments
 (0)