Skip to content

Array.cs performs an Unsafe.As cast that is an undefined behaviour #83115

@MichalPetryka

Description

@MichalPetryka

Array.cs uses Unsafe.As to cast arrays to other array types which is UB in case types don't match, it should be changed to casting the ref returned from GetArrayDataReference instead:

ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As<int[]>(array)), endIndex),

ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As<long[]>(array)), endIndex),

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions