Fixing up Utf8Parser.TryParseNumber to not fail for overly large exponents (#21233)
authorTanner Gooding <tagoo@outlook.com>
Wed, 28 Nov 2018 11:54:12 +0000 (03:54 -0800)
committerGitHub <noreply@github.com>
Wed, 28 Nov 2018 11:54:12 +0000 (03:54 -0800)
src/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Number.cs

index daa1da6..799a3fe 100644 (file)
@@ -303,10 +303,15 @@ namespace System.Buffers.Text
             {
                 if (number.Scale > int.MaxValue - (long)absoluteExponent)
                 {
-                    bytesConsumed = 0;
-                    return false;
+                    // A scale overflow means all non-zero digits are all so far to the right of the decimal point, no
+                    // number format we have will be able to see them. Just pin the scale at the absolute maximum 
+                    // and let the converter produce a 0 with the max precision available for that type.
+                    number.Scale = int.MaxValue;
+                }
+                else
+                {
+                    number.Scale += (int)absoluteExponent;
                 }
-                number.Scale += (int)absoluteExponent;
             }
 
             digits[dstIndex] = 0;