From: MichaƂ Petryka <35800402+MichalPetryka@users.noreply.github.com> Date: Wed, 8 Mar 2023 22:19:04 +0000 (+0100) Subject: Fix undefined behaviour in Array.cs (#83116) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~3578 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=57c8504b2095d15f2d70044a6cdc6b34b3f7c3ab;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Fix undefined behaviour in Array.cs (#83116) Fixes #83115 --- diff --git a/src/libraries/System.Private.CoreLib/src/System/Array.cs b/src/libraries/System.Private.CoreLib/src/System/Array.cs index a937f69..9772545 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Array.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Array.cs @@ -1332,7 +1332,7 @@ namespace System if (sizeof(T) == sizeof(byte)) { int result = SpanHelpers.IndexOfValueType( - ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As(array)), startIndex), + ref Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(array)), startIndex), Unsafe.As(ref value), count); return (result >= 0 ? startIndex : 0) + result; @@ -1340,7 +1340,7 @@ namespace System else if (sizeof(T) == sizeof(short)) { int result = SpanHelpers.IndexOfValueType( - ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As(array)), startIndex), + ref Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(array)), startIndex), Unsafe.As(ref value), count); return (result >= 0 ? startIndex : 0) + result; @@ -1348,7 +1348,7 @@ namespace System else if (sizeof(T) == sizeof(int)) { int result = SpanHelpers.IndexOfValueType( - ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As(array)), startIndex), + ref Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(array)), startIndex), Unsafe.As(ref value), count); return (result >= 0 ? startIndex : 0) + result; @@ -1356,7 +1356,7 @@ namespace System else if (sizeof(T) == sizeof(long)) { int result = SpanHelpers.IndexOfValueType( - ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As(array)), startIndex), + ref Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(array)), startIndex), Unsafe.As(ref value), count); return (result >= 0 ? startIndex : 0) + result; @@ -1580,7 +1580,7 @@ namespace System { int endIndex = startIndex - count + 1; int result = SpanHelpers.LastIndexOfValueType( - ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As(array)), endIndex), + ref Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(array)), endIndex), Unsafe.As(ref value), count); @@ -1590,7 +1590,7 @@ namespace System { int endIndex = startIndex - count + 1; int result = SpanHelpers.LastIndexOfValueType( - ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As(array)), endIndex), + ref Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(array)), endIndex), Unsafe.As(ref value), count); @@ -1600,7 +1600,7 @@ namespace System { int endIndex = startIndex - count + 1; int result = SpanHelpers.LastIndexOfValueType( - ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As(array)), endIndex), + ref Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(array)), endIndex), Unsafe.As(ref value), count); @@ -1610,7 +1610,7 @@ namespace System { int endIndex = startIndex - count + 1; int result = SpanHelpers.LastIndexOfValueType( - ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As(array)), endIndex), + ref Unsafe.Add(ref Unsafe.As(ref MemoryMarshal.GetArrayDataReference(array)), endIndex), Unsafe.As(ref value), count);