[PATCH] Fortran: Fix FMT_X/TR output into already-written content, [PR114618]
Jerry D
jvdelisle2@gmail.com
Mon Jun 15 05:05:18 GMT 2026
See attached patch which cleans up I hope the last of the tabbing issues in
formatted output. I renamed the existing test case and created a new one to
test several variations.
Comments appreciated.
Regression tested on X86_64.
Ok for mainline? No plans to backport unless someone thinks its needed.
Best regards,
Jerry
---
When an X or TR edit descriptor advances the file position into
content that has already been written (e.g. after a backward T or
TL tab), formatted_transfer_scalar_write either corrupted the
pending_spaces accounting or overwrote the existing characters with
blanks.
Fix this by detecting the case where pending_spaces is negative and
skips is positive (the advance falls within already-written content)
and using write_x (skips, 0) to move the file position forward
without overwriting. Also, for stream I/O, compute bytes_used from
fbuf->pos (the current write position) rather than fbuf->act (the
high-water mark), since the two diverge after a backward tab followed
by a partial overwrite, which previously prevented this case from
being detected for stream units.
Assisted by: Claude Sonnet 4.6
PR libfortran/114618
libgfortran/ChangeLog:
* io/transfer.c (formatted_transfer_scalar_write): Use
fbuf->pos rather than fbuf->act for bytes_used with stream
I/O. When pending_spaces is negative and skips is positive,
advance the position with write_x (skips, 0) instead of
overwriting existing content.
gcc/testsuite/ChangeLog:
* gfortran.dg/pr114618.f90: Move to...
* gfortran.dg/fmt_t_10.f90: ...here.
* gfortran.dg/fmt_t_11.f90: New test.
---
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr114618-Fortran-Fix-FMT_X-TR-output-into-already-written-con.patch
Type: text/x-patch
Size: 6348 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/fortran/attachments/20260614/a52bf852/attachment.bin>
More information about the Fortran
mailing list