From 19c023241020e3b6f5c38f47447bc0fcbe9fef5f Mon Sep 17 00:00:00 2001 From: Jerry DeLisle Date: Wed, 10 Feb 2021 19:37:52 -0800 Subject: [PATCH] libgfortran: Fix unwanted end-of-record by checking if seen_dollar. libgfortran/ChangeLog: PR libfortran/98825 * io/transfer.c (next_record_w): Insert check for seen_dollar and if so, skip issueing next record. gcc/testsuite/ChangeLog: PR libfortran/98825 * gfortran.dg/dollar_edit_descriptor_4.f: New test. --- .../gfortran.dg/dollar_edit_descriptor_4.f | 16 ++++++++++++++++ libgfortran/io/transfer.c | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/dollar_edit_descriptor_4.f diff --git a/gcc/testsuite/gfortran.dg/dollar_edit_descriptor_4.f b/gcc/testsuite/gfortran.dg/dollar_edit_descriptor_4.f new file mode 100644 index 00000000000..c8453ce6bc8 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dollar_edit_descriptor_4.f @@ -0,0 +1,16 @@ +! { dg-do run } +! { dg-options "-std=gnu" } +! PR98825 Test for fix of '$' edit descriptor. + character(30) :: line + 10 format (i3,$) + + open(10, status='scratch') + write (10,10) 1 + write (10,10) 2,3,4,5 +! Check the result. + line = 'abcdefg' + rewind(10) + read(10, '(a)') line + close(10) + if (line .ne. ' 1 2 3 4 5') call abort + end diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 8ab0583dd55..27bee9d4e01 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -4020,6 +4020,8 @@ next_record_w (st_parameter_dt *dtp, int done) } } } + else if (dtp->u.p.seen_dollar == 1) + break; /* Handle legacy CARRIAGECONTROL line endings. */ else if (dtp->u.p.current_unit->flags.cc == CC_FORTRAN) next_record_cc (dtp); -- 2.30.2