From 33b2b069c16e53592936095575852e3fe7b43ec3 Mon Sep 17 00:00:00 2001 From: Jerry DeLisle Date: Sun, 14 Jan 2018 17:36:29 +0000 Subject: [PATCH] re PR libfortran/83811 (fortran 'e' format broken for single digit exponents) 2018-01-18 Jerry DeLisle 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 | 5 +++++ gcc/testsuite/gfortran.dg/fmt_e.f90 | 10 ++++++++++ libgfortran/ChangeLog | 5 +++++ libgfortran/io/write.c | 5 +++-- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/fmt_e.f90 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 143d59cb970..dfc1345ea01 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-18 Jerry DeLisle + + PR libgfortran/83811 + * gfortran.dg/fmt_e.f90: New test. + 2018-01-14 H.J. Lu * 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 index 00000000000..a85506b0929 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/fmt_e.f90 @@ -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 + diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 022725fdcdc..d86151b2051 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,8 @@ +2018-01-18 Jerry DeLisle + + PR libgfortran/83811 + * write.c (select_buffer): Adjust buffer size up by 1. + 2018-01-08 Janne Blomqvist PR 78534, bugfix for r256322 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); -- 2.30.2