Better ArraySegment .ctor tests (dotnet/coreclr#9800)
authorBen Adams <thundercat@illyriad.co.uk>
Sun, 26 Feb 2017 00:02:14 +0000 (00:02 +0000)
committerJan Kotas <jkotas@microsoft.com>
Sun, 26 Feb 2017 00:02:14 +0000 (16:02 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/43647666150a40fd78caf1c58b2cc62e322f1e21

src/coreclr/src/mscorlib/src/System/ArraySegment.cs

index 98e0b79..fa02938 100644 (file)
@@ -45,8 +45,9 @@ namespace System
         public ArraySegment(T[] array, int offset, int count)
         {
             // Validate arguments, check is minimal instructions with reduced branching for inlinable fast-path
+            // Negative values discovered though conversion to high values when converted to unsigned
             // Failure should be rare and location determination and message is delegated to failure functions
-            if (array == null || (offset | count) < 0 || (array.Length - offset < count))
+            if (array == null || (uint)offset > (uint)array.Length || (uint)count > (uint)(array.Length - offset))
                 ThrowHelper.ThrowArraySegmentCtorValidationFailedExceptions(array, offset, count);
             Contract.EndContractBlock();