diff mbox series

[libgfortran] PR90374 Zero width format specifiers.

Message ID c444325c-35e7-42f0-cdb1-a39b08db4870@gmail.com
State New
Headers show
Series [libgfortran] PR90374 Zero width format specifiers. | expand

Commit Message

Jerry D Jan. 12, 2020, 3:54 p.m. UTC
Hi all,

The attached patch is simple enough. Zero width exponent format 
specifier is not allowed with "D" editing.

Also, needed to adjust the width calculated for exponents greater than 
999 for the larger kind cases (real 10 and real 16).

Regression tested on x86_64.  I will commit as soon as I include in the 
test case.

Regards,

Jerry

2020-01-12  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

     PR libfortran/90374
     * io/format.c (parse_format_list): Zero width not allowed with
     FMT_D.
     * io/write_float.def (build_float_string): Include range of
     higher exponent values that require wider width.
diff mbox series

Patch

diff --git a/libgfortran/io/format.c b/libgfortran/io/format.c
index b42a5593e38..3be861fb19c 100644
--- a/libgfortran/io/format.c
+++ b/libgfortran/io/format.c
@@ -954,7 +954,9 @@  parse_format_list (st_parameter_dt *dtp, bool *seen_dd)
 	    }
 	  tail->u.real.d = fmt->value;
 	  
-	  /* Look for optional exponent */
+	  /* Look for optional exponent, not allowed for FMT_D */
+	  if (t == FMT_D)
+	    break;
 	  u = format_lex (fmt);
 	  if (u != FMT_E)
 	    fmt->saved_token = u;
diff --git a/libgfortran/io/write_float.def b/libgfortran/io/write_float.def
index 75c7942c4c5..8a1be054371 100644
--- a/libgfortran/io/write_float.def
+++ b/libgfortran/io/write_float.def
@@ -497,7 +497,9 @@  build_float_string (st_parameter_dt *dtp, const fnode *f, char *buffer,
       else if (f->u.real.e == 0)
 	{
 	  /* Zero width specified, no leading zeros in exponent  */
-	  if (e > 99 || e < -99)
+	  if (e > 999 || e < -999)
+	    edigits = 6;
+	  else if (e > 99 || e < -99)
 	    edigits = 5;
 	  else if (e > 9 || e < -9)
 	    edigits = 4;