https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128107
--- Comment #7 from Juno Krahn <juno.krahn at gmail dot com> ---
Test code updated with information, testing with CRLF.
The error is file position corruption after a short read with STREAM,
ADVANCE='no'. This will corrupt future data reads. The file position INQUIRE
error persists through remainder of file reading.
I then re-generate the test data file with CRLF endings, run the same test, and
position corruption does not happen. I think I figured out the source of
corruption, but I can't make sense of why CRLF changes the outcome.
In libgfortran/io/transfer.c around line 565 in read_block_form() strm_pos is
adjusted by bytes read PLUS the seen_eor flag:
if (is_internal_unit (dtp))
source = read_sf_internal (dtp, nbytes);
else
source = read_sf (dtp, nbytes);
dtp->u.p.current_unit->strm_pos +=
(gfc_offset) (*nbytes + dtp->u.p.sf_seen_eor);
With a short read, read_block_form() continues to be called after EOR
condition, and read incrementing the strm_pos for each call, corrupting POS
inquiries until reset with rewind or seek.
The fix may be modify read_block_form() to track whether eor was already set
before calling read_sf(), or to prevent additional calls by
formatted_transfer_scalar_read() checking dtp->u.p.eor_condition inside the
for(;;) loop and not just at the beginning.