Skip to content

Cast in BIT_initCStream #309

@heroicpixel

Description

@heroicpixel

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions