Re: [PATCH 0/5] const-correctness in grep.c
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 22, 2021, 18:57 UTC
- Message-ID
- <xmqqlf3o780a.fsf@gitster.g>
- In-Reply-To
- <YUlVZk1xXulAqdef@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 6 quoted lines
> While discussing [1], I noticed that the grep code mostly takes > non-const buffers, even though it is conceptually a read-only operation > to search in them. The culprit is a handful of spots that temporarily > tie off NUL-terminated strings by overwriting a byte of the buffer and > then restoring it. But I think we no longer need to do so these days, > now that we have a regexec_buf() that can take a ptr/size pair.
Yes, the haystack has not been read-only exactly because we didn't have <ptr,size> based regexec variant when the grep machinery was written, and there is no reason why we want to use the "temporarily terminate by swapping the byte with a NUL" trick.
It always is a pleasure to read such a concise and to-the-point summary. With a clear summary like that, a reader almost does not have to see the patch to guess how the rest of the story goes ;-)