Fix impl of ReadOnlySpan ToLower/ToUpper for Unix. (#16496)
authorAhson Khan <ahkha@microsoft.com>
Thu, 22 Feb 2018 16:02:20 +0000 (08:02 -0800)
committerGitHub <noreply@github.com>
Thu, 22 Feb 2018 16:02:21 +0000 (08:02 -0800)
src/mscorlib/shared/System/Globalization/TextInfo.Unix.cs

index 5186394..d13d3e8 100644 (file)
@@ -81,24 +81,26 @@ namespace System.Globalization
                 {
                     if (IsAsciiCasingSameAsInvariant)
                     {
-                        int length = source.Length;
+                        int length = 0;
                         char* a = pSource, b = pResult;
                         if (toUpper)
                         {
-                            while (length-- != 0 && *a < 0x80)
+                            while (length < source.Length && *a < 0x80)
                             {
                                 *b++ = ToUpperAsciiInvariant(*a++);
+                                length++;
                             }
                         }
                         else
                         {
-                            while (length-- != 0 && *a < 0x80)
+                            while (length < source.Length && *a < 0x80)
                             {
                                 *b++ = ToLowerAsciiInvariant(*a++);
+                                length++;
                             }
                         }
 
-                        if (length != 0)
+                        if (length != source.Length)
                         {
                             ChangeCase(a, source.Length - length, b, destination.Length - length, toUpper);
                         }