Date: Fri, 27 Feb 2026 10:05:53 +0000 From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: d851e0070499 - stable/15 - ngctl: Fix getline loop Message-ID: <69a16c81.30858.65dde7ed@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/15 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=d851e0070499b8b34f3cf1efb956aefa6faf6859 commit d851e0070499b8b34f3cf1efb956aefa6faf6859 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-24 14:23:39 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-27 10:05:26 +0000 ngctl: Fix getline loop I misremembered when I wrote this code: getline() returns -1 on EOF, not zero, so the loop condition and the error check are both incorrect (though in practice getline() will never return 0). MFC after: 3 days Fixes: 3cbdcabf714d ("ngctl: Modernize code somewhat") Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D55487 (cherry picked from commit 6c4777c59325c2cfefcce0c466b3bf475404a550) --- usr.sbin/ngctl/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr.sbin/ngctl/main.c b/usr.sbin/ngctl/main.c index b58de1e042b3..2b711fd4155a 100644 --- a/usr.sbin/ngctl/main.c +++ b/usr.sbin/ngctl/main.c @@ -243,7 +243,7 @@ ReadFile(FILE *fp) unsigned int lineno = 0; int rtn = CMDRTN_OK; - while ((len = getline(&line, &sz, fp)) > 0) { + while ((len = getline(&line, &sz, fp)) >= 0) { lineno++; if (*line == '#') continue; @@ -252,7 +252,7 @@ ReadFile(FILE *fp) break; } } - if (len < 0) + if (ferror(fp)) rtn = CMDRTN_ERROR; free(line); return (rtn);home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69a16c81.30858.65dde7ed>
