Re: [RFC] cocci: .buf in a strbuf object can never be NULL
- From
Jeff King <peff@peff.net>
- Date
- Mar 21, 2026, 16:41 UTC
- Message-ID
- <20260321164131.GA717199@coredump.intra.peff.net>
- In-Reply-To
- <bed43331-ad9d-437c-a56a-94a50877f719@web.de>
On Sat, Mar 21, 2026 at 02:14:51PM +0100, René Scharfe wrote:
Show 12 quoted lines
> > if (feof(fp)) > > return EOF; > > > > strbuf_reset(sb); > [...] > > I think the strbuf_reset() could go away even without any other changes. > > We always adjust sb->len in the end to match what happened with > > getdelim(), so there is no point in doing it up front. > > Yes. Same with the EOF check; getdelim(3) is (must be) prepared to handle > that for us. An early return at the end of the file avoids the translate > effort once per file, but adds the cost of checking for each line.
I think you're probably right. I added it in the original as an attempt to simplify away a tricky case before manipulating the strbuf, but we have to eventually deal with those tricky cases anyway, since we may see the EOF fresh from getdelim().
-Peff