LastIndexOf corner case fix when span is empty (dotnet/coreclr#18826)
authorViktor Hofer <viktor.hofer@microsoft.com>
Sun, 8 Jul 2018 17:41:40 +0000 (19:41 +0200)
committerGitHub <noreply@github.com>
Sun, 8 Jul 2018 17:41:40 +0000 (19:41 +0200)
Commit migrated from https://github.com/dotnet/coreclr/commit/018dc20cc8f5815867c30b22a4973702ce4716c4

src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Fast.cs

index 58d0b5c..4e84223 100644 (file)
@@ -188,7 +188,7 @@ namespace System
 
             if (value.Length == 0)
             {
-                return span.Length - 1;
+                return span.Length > 0 ? span.Length - 1 : 0;
             }
 
             if (span.Length == 0)