On Thu, May 7, 2026 at 4:55 PM Duncan Roe <[email protected]> wrote:
> > - include config.h to fix build (e.g., with unlocked-io) STYLE ONLY
I can't recall now why the include order matters, but this order resolved a
`use of undeclared identifier 'fputc_unlocked'` error, similar to [1].
> The original code is correct. The effect of including this patch is that rev
> with no arguments is a no-op. rev with no arguments *should* read lines from
> standard input (fd 0).
Sorry, I added a new issue while fixing a corner case.
The (not very likely!) issue I was trying to address happens if rev is invoked
while FD 0 is closed:
$ (rev /dev/null; ls -l /proc/self/fd/0) <&-
lr-x------ 1 vm vm 64 May 7 19:14 /proc/self/fd/0 -> /dev/null
The fd opened for reading will be 0, so the code
if (fd != 0)
close(fd)
will fail to close it, leaving FD 0 opened to the file that was read, even after
rev exits.
> Grisha, did you by any chance use some AI tool to create your reply? If so,
> it's
> quite good - it did find 3 real bugs: what tool was it? If not, I take my hat
> off to you for finding them.
No AI tool, just a build with ASAN enabled.
[1] https://lists.gnu.org/archive/html/bug-bash/2024-02/msg00125.html