>From a9a402bea1ba1df9dc14968c12e21b9ecc44260b Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 23 Nov 2026 08:07:28 -0500 Subject: [PATCH] getdelim: fix signedness error breaking unbuffered delimiter matching in the code path where the delimiter was not found in the FILE buffer and getc_unlocked is used to inspect the next byte and potentially refill the buffer, the byte read was wrongly converted to type char before comparing it against the delimiter. on archs where plain char is signed, this prevented matching of a delimiter with the high bit set. for unbuffered FILEs, matching was consistently broken. otherwise, hitting the bug was dependent on where the delimiter fell relative to buffering boundaries. --- src/stdio/getdelim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdio/getdelim.c b/src/stdio/getdelim.c index df114441..e4a51182 100644 --- a/src/stdio/getdelim.c +++ b/src/stdio/getdelim.c @@ -71,7 +71,7 @@ ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restric /* If the byte read by getc won't fit without growing the * output buffer, push it back for next iteration. */ if (i+1 >= *n) *--f->rpos = c; - else if (((*s)[i++] = c) == delim) break; + else if ((*s)[i++] = c, c == delim) break; } (*s)[i] = 0; -- 2.21.0