From: Jeremy Koritzinsky Date: Tue, 25 Sep 2018 23:45:04 +0000 (-0700) Subject: Simpler implementation from PR feedback. X-Git-Tag: accepted/tizen/unified/20190422.045933~1126^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=35dff1a2277d583b9d554c853bc4b9a31f6f79a0;p=platform%2Fupstream%2Fcoreclr.git Simpler implementation from PR feedback. --- diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeBuffer.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeBuffer.cs index 66b500a..74edae3 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeBuffer.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeBuffer.cs @@ -110,19 +110,13 @@ namespace System.Runtime.InteropServices [CLSCompliant(false)] public void Initialize(uint numElements, uint sizeOfEachElement) { - if (sizeOfEachElement == 0) + try { - _numBytes = (UIntPtr)0; + _numBytes = checked((UIntPtr)((ulong)numElements * sizeOfEachElement)); } - else + catch (OverflowException) { - if (IntPtr.Size == 4 && numElements > uint.MaxValue / sizeOfEachElement) - throw new ArgumentOutOfRangeException("numBytes", SR.ArgumentOutOfRange_AddressSpace); - - if (numElements >= (ulong)Uninitialized / sizeOfEachElement) - throw new ArgumentOutOfRangeException(nameof(numElements), SR.ArgumentOutOfRange_UIntPtrMax); - - _numBytes = checked((UIntPtr)(numElements * sizeOfEachElement)); + throw new ArgumentOutOfRangeException("numBytes", SR.ArgumentOutOfRange_AddressSpace); } }