Hello all,

I committed the following as trivial.

Regression tested on x86_64-pc-linux-gnu.

This is a regression on 7 so I will backport.

Regards,

Jerry

2018-01-18  Jerry DeLisle  <jvdeli...@gcc.gnu.org>

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

diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c
index 8021a1e9c4b..28ea852867b 100644
--- a/libgfortran/io/write.c
+++ b/libgfortran/io/write.c
@@ -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);

New test case:

! { 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

Reply via email to