The master branch has been updated by Jerry DeLisle <[email protected]>:

https://gcc.gnu.org/g:56c7766c4ee32142c9ebede80bfed7ba349f958a

commit r17-6738-g56c7766c4ee32142c9ebede80bfed7ba349f958a

On 11/26/26 10:15 AM, Jerry DeLisle wrote:
See attached patch.

When a formatted STREAM read asks for more items than the record
holds, read_sf sees the end of record on the first item past it and
returns a zero length for each later item. read_block_form still added
the record terminator length to the stream position on every one of
those calls, so INQUIRE POS= ends up one byte ahead per extra item, two
with CRLF. The file offset itself is right, so only POS= and anything
positioned from it go wrong.

The fix is in read_block_form in transfer.c, plus the one-line read_x
change in read.c; the rest is the new test, which covers LF and CRLF
records.

Regression tested on x86_64.

I plan to commit this as simple and obvious.

Regards,

Jerry

---

libgfortran: [PR128107] Wrong POS after formatted STREAM read past EOR

A formatted STREAM read whose input list goes past the end of a record
left the unit position ahead by the record terminator length for each
further item, so INQUIRE POS= was wrong and a later read or write at
that position started in the wrong place.  This is because
read_block_form counted the terminator on every call after the end of
record was seen, although only the first call consumes it.  The patch
counts it only on that call, and makes read_x count it as well, since
X, TR or T editing past the end of a record consumed the terminator
without counting it.

Assisted-by: Claude Opus 5.5

        PR libfortran/128107

libgfortran/ChangeLog:

        * io/read.c (read_x): Count the record terminator in the stream
        position when it is consumed.
        * io/transfer.c (read_block_form): Count the record terminator in
        the stream position only on the read that consumes it.

gcc/testsuite/ChangeLog:

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

Reply via email to