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

From: René Scharfe <[email-masked]>
Date: Sat, 21 Mar 2026 14:14:51 +0100

On 3/20/26 5:18 AM, Jeff King wrote:
> 
>           ssize_t r;
>   
>           if (feof(fp))
>                   return EOF;
>   
>           strbuf_reset(sb);
>   
>           /* Translate slopbuf to NULL, as we cannot call realloc on it */
>           if (!sb->alloc)
>                   sb->buf = NULL;
>           errno = 0;
> 
> 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.

René