Subject: Re: [RFC] cocci: .buf in a strbuf object can never be NULL

From: Jeff King <[email-masked]>
Date: Sat, 21 Mar 2026 12:41:31 -0400

On Sat, Mar 21, 2026 at 02:14:51PM +0100, René Scharfe wrote:

> >           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