Skip to content

Commit ffed02c

Browse files
michielp1807folkertdev
authored andcommitted
Clean up as_ptr() followed by add(...) or offset(...)
This makes sure the bounds are checked
1 parent 3d3e844 commit ffed02c

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

lib/dictBuilder/zdict.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ unsafe fn analyze_entropy_internal(
946946
&mut matchLengthCount,
947947
&mut litLengthCount,
948948
&mut repOffset,
949-
src.as_ptr().add(pos) as *const core::ffi::c_void,
949+
src[pos..].as_ptr() as *const core::ffi::c_void,
950950
*fileSize,
951951
notificationLevel,
952952
);
@@ -1127,15 +1127,9 @@ unsafe fn analyze_entropy_internal(
11271127
return Err(Error::dstSize_tooSmall);
11281128
}
11291129

1130-
MEM_writeLE32(dstPtr as *mut core::ffi::c_void, *repStartValue.as_ptr());
1131-
MEM_writeLE32(
1132-
dstPtr.add(4) as *mut core::ffi::c_void,
1133-
*repStartValue.as_ptr().add(1),
1134-
);
1135-
MEM_writeLE32(
1136-
dstPtr.add(8) as *mut core::ffi::c_void,
1137-
*repStartValue.as_ptr().add(2),
1138-
);
1130+
MEM_writeLE32(dstPtr as *mut core::ffi::c_void, repStartValue[0]);
1131+
MEM_writeLE32(dstPtr.add(4) as *mut core::ffi::c_void, repStartValue[1]);
1132+
MEM_writeLE32(dstPtr.add(8) as *mut core::ffi::c_void, repStartValue[2]);
11391133

11401134
Ok(eSize.wrapping_add(12))
11411135
}
@@ -1516,9 +1510,7 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
15161510
}
15171511
memcpy(
15181512
ptr as *mut core::ffi::c_void,
1519-
samples
1520-
.as_ptr()
1521-
.offset((*dictList.offset(u as isize)).pos as isize)
1513+
samples[(*dictList.offset(u as isize)).pos as usize..].as_ptr()
15221514
as *const core::ffi::c_void,
15231515
l as size_t,
15241516
);

0 commit comments

Comments
 (0)