re PR libfortran/83811 (fortran 'e' format broken for single digit exponents)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 14 Jan 2018 17:36:29 +0000 (17:36 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 14 Jan 2018 17:36:29 +0000 (17:36 +0000)
2018-01-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

        PR libgfortran/83811
        * write.c (select_buffer): Adjust buffer size up by 1.

        * gfortran.dg/fmt_e.f90: New test.

From-SVN: r256669

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/fmt_e.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/io/write.c

index 143d59cb970142173d316d57acfc002a011ae7fa..dfc1345ea0104cee2ca60828b100da5f08ef9ec2 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/83811
+       * gfortran.dg/fmt_e.f90: New test.
+
 2018-01-14  H.J. Lu  <hongjiu.lu@intel.com>
 
        * gcc.target/i386/indirect-thunk-10.c: New test.
diff --git a/gcc/testsuite/gfortran.dg/fmt_e.f90 b/gcc/testsuite/gfortran.dg/fmt_e.f90
new file mode 100644 (file)
index 0000000..a85506b
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do run }
+! PR83811 fortran 'e' format broken for single digit exponents
+program test
+  character(25) :: s
+  write(s, '(1pe5.0e1)') 1.e-4
+  if (s.ne."1.E-4") call abort
+  write(s, '(e5.1e1)') 1.e12
+  if (s.ne."*****") call abort
+end
+      
index 022725fdcdca6533a2f7a70933c87c45a86f58a9..d86151b2051b7f48398f87257e4b4456bde3c18e 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/83811
+       * write.c (select_buffer): Adjust buffer size up by 1.
+
 2018-01-08  Janne Blomqvist  <jb@gcc.gnu.org>
 
        PR 78534, bugfix for r256322
index 8021a1e9c4b0202e5a36293f9e8d3a15cf231670..28ea852867b7e7f3713ebeef393600a196ebb0d1 100644 (file)
@@ -1519,8 +1519,9 @@ select_buffer (st_parameter_dt *dtp, const fnode *f, int precision,
 {
   char *result;
   
-  /* The buffer needs at least one more byte to allow room for normalizing.  */
-  *size = size_from_kind (dtp, f, kind) + precision + 1;
+  /* The buffer needs at least one more byte to allow room for
+     normalizing and 1 to hold null terminator.  */
+  *size = size_from_kind (dtp, f, kind) + precision + 1 + 1;
 
   if (*size > BUF_STACK_SZ)
      result = xmalloc (*size);