diff --git a/nanoFramework.CoreLibrary/System/SpanByte.cs b/nanoFramework.CoreLibrary/System/SpanByte.cs index aaf1b1e1..9c248a4d 100644 --- a/nanoFramework.CoreLibrary/System/SpanByte.cs +++ b/nanoFramework.CoreLibrary/System/SpanByte.cs @@ -42,7 +42,10 @@ public SpanByte(byte[] array, int start, int length) { if (array != null) { - if ((length > array.Length - start) || (start > array.Length)) + if (start < 0 || + length < 0 || + start + length > array.Length || + (start == array.Length && start > 0)) { throw new ArgumentOutOfRangeException($"Array length too small"); } @@ -69,7 +72,7 @@ public byte this[int index] { get { - if (index > _length) + if (index >= _length) { throw new ArgumentOutOfRangeException($"Index out of range"); } @@ -78,7 +81,7 @@ public byte this[int index] } set { - if (index > _length) + if (index >= _length) { throw new ArgumentOutOfRangeException($"Index out of range"); } @@ -131,12 +134,7 @@ public void CopyTo(SpanByte destination) /// start is less than zero or greater than System.Span.Length. public SpanByte Slice(int start) { - if ((start > _length) || (start < 0)) - { - throw new ArgumentOutOfRangeException($"start is less than zero or greater than length"); - } - - return new SpanByte(_array, _start + start, _length - start); + return Slice(start, _length - start); } ///