diff --git a/src/Ramstack.FileSystem.Globbing/Internal/PathHelper.cs b/src/Ramstack.FileSystem.Globbing/Internal/PathHelper.cs index 8afe664..e9ba214 100644 --- a/src/Ramstack.FileSystem.Globbing/Internal/PathHelper.cs +++ b/src/Ramstack.FileSystem.Globbing/Internal/PathHelper.cs @@ -111,7 +111,10 @@ public static ReadOnlySpan GetPartialPattern(string pattern, int depth) if (depth < 1 || r.final == length || IsGlobStar(ref s, r.start, r.final)) + { + Debug.Assert(r.final >= 0 && r.final <= pattern.Length); return MemoryMarshal.CreateReadOnlySpan(ref s, r.final); + } } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -246,7 +249,7 @@ public PathSegmentIterator() => return (start, _last); } - if (Avx2.IsSupported && (int)_position + Vector256.Count <= length) + if (Avx2.IsSupported && (int)_position <= length - Vector256.Count) { var chunk = LoadVector256(ref source, _position); var slash = Vector256.Create((ushort)'/'); @@ -266,7 +269,7 @@ public PathSegmentIterator() => if (_mask == 0) _position += Vector256.Count; } - else if (Sse2.IsSupported && !Avx2.IsSupported && (int)_position + Vector128.Count <= length) + else if (Sse2.IsSupported && !Avx2.IsSupported && (int)_position <= length - Vector128.Count) { var chunk = LoadVector128(ref source, _position); var slash = Vector128.Create((ushort)'/'); @@ -286,7 +289,7 @@ public PathSegmentIterator() => if (_mask == 0) _position += Vector128.Count; } - else if (AdvSimd.Arm64.IsSupported && (int)_position + Vector128.Count <= length) + else if (AdvSimd.Arm64.IsSupported && (int)_position <= length - Vector128.Count) { var chunk = LoadVector128(ref source, _position); var slash = Vector128.Create((ushort)'/');