PR24944, gas doesn't read enough digits when parsing a floating point number

Message ID 20191120113208.GR13199@bubble.grove.modra.org
State New
Headers show
Series
  • PR24944, gas doesn't read enough digits when parsing a floating point number
Related show

Commit Message

Alan Modra Nov. 20, 2019, 11:32 a.m.
PR 24944
	* atof-generic.c (atof_generic): Increase decimal guard digits.
	* testsuite/gas/i386/fp.s: Add more tests.
	* testsuite/gas/i386/fp.d: Update.


-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/gas/atof-generic.c b/gas/atof-generic.c
index 345ccef2c1..8807cc5605 100644
--- a/gas/atof-generic.c
+++ b/gas/atof-generic.c
@@ -347,11 +347,12 @@  atof_generic (/* return pointer to just AFTER number we read.  */
 		   - address_of_generic_floating_point_number->low
 		   + 1);	/* Number of destination littlenums.  */
 
-      /* Includes guard bits (two littlenums worth) */
-      maximum_useful_digits = (((precision - 2))
-			       * ( (LITTLENUM_NUMBER_OF_BITS))
-			       * 1000000 / 3321928)
-	+ 2;			/* 2 :: guard digits.  */
+      /* precision includes two littlenums worth of guard bits,
+	 so this gives us 10 decimal guard digits here.  */
+      maximum_useful_digits = (precision
+			       * LITTLENUM_NUMBER_OF_BITS
+			       * 1000000 / 3321928
+			       + 1);	/* round up.  */
 
       if (number_of_digits_available > maximum_useful_digits)
 	{
diff --git a/gas/testsuite/gas/i386/fp.d b/gas/testsuite/gas/i386/fp.d
index a9a9538cd0..edf79ff999 100644
--- a/gas/testsuite/gas/i386/fp.d
+++ b/gas/testsuite/gas/i386/fp.d
@@ -4,6 +4,8 @@ 
 .*:     file format .*
 
 Contents of section .data:
- 0000 00881bcd 4b789ad4 004071a3 79094f93  ....Kx...@q.y.O.
- 0010 0a40789a 5440789a 54400000 00000000  .@x.T@x.T@......
- 0020 e65e1710 20395e3b e65e1710 20395e3b  .\^.. 9\^;.\^.. 9\^;
+ 0000 00881bcd 4b789ad4 004071a3 79094f93  .*
+ 0010 0a40789a 5440789a 54400000 00000000  .*
+ 0020 e65e1710 20395e3b e65e1710 20395e3b  .*
+ 0030 00000000 0000a044 01000000 0000a044  .*
+ 0040 00000000 0000f03f .*
diff --git a/gas/testsuite/gas/i386/fp.s b/gas/testsuite/gas/i386/fp.s
index a1f2b0f0a4..11a50cf268 100644
--- a/gas/testsuite/gas/i386/fp.s
+++ b/gas/testsuite/gas/i386/fp.s
@@ -15,3 +15,8 @@ 
 # The assembler used to treat the next value as zero instead of 1e-22.
         .double .0000000000000000000001
         .double 1e-22
+# The assembler used to limit the number of digits too much.
+	.double 37778931862957165903871.0
+	.double 37778931862957165903873.0
+# Ensure we handle a crazy number of digits
+	.double 1.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001