Skip to content

Commit 307161a

Browse files
committed
fn ZDICT_insertSortCount: make safe
1 parent 51d4f49 commit 307161a

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

lib/dictBuilder/zdict.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -832,22 +832,21 @@ unsafe fn ZDICT_totalSampleSize(fileSizes: *const size_t, nbFiles: core::ffi::c_
832832
}
833833
total
834834
}
835-
unsafe fn ZDICT_insertSortCount(table: *mut offsetCount_t, val: u32, count: u32) {
836-
let mut u: u32 = 0;
837-
(*table.offset(ZSTD_REP_NUM as isize)).offset = val;
838-
(*table.offset(ZSTD_REP_NUM as isize)).count = count;
839-
u = ZSTD_REP_NUM as u32;
835+
836+
fn ZDICT_insertSortCount(table: &mut [offsetCount_t; 4], val: u32, count: u32) {
837+
let mut u = 0usize;
838+
table[ZSTD_REP_NUM as usize] = offsetCount_t { offset: val, count };
840839
while u > 0 {
841840
let mut tmp = offsetCount_t {
842841
offset: 0,
843842
count: 0,
844843
};
845-
if (*table.offset(u.wrapping_sub(1) as isize)).count >= (*table.offset(u as isize)).count {
844+
if (table[u.wrapping_sub(1)]).count >= (table[u]).count {
846845
break;
847846
}
848-
tmp = *table.offset(u.wrapping_sub(1) as isize);
849-
*table.offset(u.wrapping_sub(1) as isize) = *table.offset(u as isize);
850-
*table.offset(u as isize) = tmp;
847+
tmp = table[u.wrapping_sub(1)];
848+
table[u.wrapping_sub(1)] = table[u];
849+
table[u] = tmp;
851850
u = u.wrapping_sub(1);
852851
}
853852
}
@@ -1032,11 +1031,7 @@ unsafe fn ZDICT_analyzeEntropy(
10321031
let mut offset: u32 = 0;
10331032
offset = 1;
10341033
while offset < MAXREPOFFSET as u32 {
1035-
ZDICT_insertSortCount(
1036-
bestRepOffset.as_mut_ptr(),
1037-
offset,
1038-
*repOffset.as_mut_ptr().offset(offset as isize),
1039-
);
1034+
ZDICT_insertSortCount(&mut bestRepOffset, offset, repOffset[offset as usize]);
10401035
offset = offset.wrapping_add(1);
10411036
}
10421037
total = 0;

0 commit comments

Comments
 (0)