From: enh Subject: [PATCH] fix getdelim() EOF behavior To: OpenBSD Tech Date: Thu, 9 Oct 2025 16:25:21 -0400 corresponds to glibc bug https://sourceware.org/bugzilla/show_bug.cgi?id=28038... basically just "make sure you've terminated the buffer _before_ returning". diff --git a/lib/libc/stdio/getdelim.c b/lib/libc/stdio/getdelim.c index d709a3d18e1..292920e79c9 100644 --- a/lib/libc/stdio/getdelim.c +++ b/lib/libc/stdio/getdelim.c @@ -119,13 +119,11 @@ getdelim(char **__restrict buf, size_t *__restrict buflen, FUNLOCKFILE(fp); - /* POSIX demands we return -1 on EOF. */ - if (off == 0) - return -1; - if (*buf != NULL) *(*buf + off) = '\0'; - return off; + + /* POSIX demands we return -1 on EOF. */ + return (off == 0) ? -1 : off; error: fp->_flags |= __SERR;