Fix Span length in TryFormatUInt64Slow (#34840)
authorAndrew Au <andrewau@microsoft.com>
Wed, 15 Apr 2020 16:00:28 +0000 (09:00 -0700)
committerGitHub <noreply@github.com>
Wed, 15 Apr 2020 16:00:28 +0000 (09:00 -0700)
* Make the Span length right

* Adding a regression test for the span problem

* Avoid dependency on machine locale

* Using customFormat

src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs
src/libraries/System.Runtime/tests/System/UInt64Tests.cs

index 74fe7c0..9cba193 100644 (file)
@@ -1069,7 +1069,7 @@ namespace System
                     NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);
 
                     byte* pDigits = stackalloc byte[UInt64NumberBufferLength];
-                    NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, UInt32NumberBufferLength);
+                    NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, UInt64NumberBufferLength);
 
                     UInt64ToNumber(value, ref number);
 
index fac4535..0cb48df 100644 (file)
@@ -120,6 +120,7 @@ namespace System.Tests
             yield return new object[] { (ulong)123, "E", customFormat, "1~230000E&002" };
             yield return new object[] { (ulong)123, "F", customFormat, "123~00" };
             yield return new object[] { (ulong)123, "P", customFormat, "12,300.00000 @" };
+            yield return new object[] { ulong.MaxValue, "n5", customFormat, "18*446*744*073*709*551*615~00000" };
         }
 
         [Theory]