Hi team!
We used AI in writing this issue description.
We noticed a small casting detail in the implementation of BIT_initCStream.
Currently, during the offset subtraction, there is an intermediate cast to core::ffi::c_ulong before casting to isize:
(*bitC).endPtr = ((*bitC).startPtr)
.add(dstCapacity)
.offset(-(::core::mem::size_of::<BitContainerType>() as core::ffi::c_ulong as isize));
On 64-bit Windows (LLP64 data model), core::ffi::c_ulong is 32-bit whereas isize is 64-bit. Casting the usize returned by size_of to a 32-bit c_ulong before converting it to a 64-bit isize could technically result in truncation if the type size were ever extremely large.
Would it be possible to safely simplify this by casting directly to isize?
To Reproduce
N/A
Expected behavior
N/A
Screenshots and charts
N/A
Desktop (please complete the following information):
- OS: Windows (64-bit LLP64 targets)
- Compiler: MSVC / Rustc targeting
x86_64-pc-windows-msvc
- Build system: cargo / build.rs
Additional context
Direct link to the line:
|
.offset(-(::core::mem::size_of::<BitContainerType>() as core::ffi::c_ulong as isize)); |
Thank you so much for your time and hard work on this project!
Hi team!
We used AI in writing this issue description.
We noticed a small casting detail in the implementation of
BIT_initCStream.Currently, during the offset subtraction, there is an intermediate cast to
core::ffi::c_ulongbefore casting toisize:On 64-bit Windows (LLP64 data model),
core::ffi::c_ulongis 32-bit whereasisizeis 64-bit. Casting theusizereturned bysize_ofto a 32-bitc_ulongbefore converting it to a 64-bitisizecould technically result in truncation if the type size were ever extremely large.Would it be possible to safely simplify this by casting directly to
isize?To Reproduce
N/A
Expected behavior
N/A
Screenshots and charts
N/A
Desktop (please complete the following information):
x86_64-pc-windows-msvcAdditional context
Direct link to the line:
libzstd-rs-sys/lib/common/bitstream.rs
Line 33 in 3dc8c85
Thank you so much for your time and hard work on this project!