Re: [RFC] cocci: .buf in a strbuf object can never be NULL
- From
René Scharfe <l.s.r@web.de>
- Date
- Mar 21, 2026, 13:14 UTC
- Message-ID
- <bed43331-ad9d-437c-a56a-94a50877f719@web.de>
- In-Reply-To
- <20260320041803.GA18125@coredump.intra.peff.net>
On 3/20/26 5:18 AM, Jeff King wrote:
Show 16 quoted lines
> > 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é