Re: [PATCH v4 3/3] regex: use regexec_buf()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 21, 2016, 20:09 UTC
- Message-ID
- <xmqqintp6mm8.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <xmqqmvj16p06.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 13 quoted lines
> Johannes Schindelin <johannes.schindelin@gmx.de> writes: > >> The new regexec_buf() function operates on buffers with an explicitly >> specified length, rather than NUL-terminated strings. >> >> We need to use this function whenever the buffer we want to pass to >> regexec() may have been mmap()ed (and is hence not NUL-terminated). >> >> Note: the original motivation for this patch was to fix a bug where >> `git diff -G <regex>` would crash. This patch converts more callers, >> though, some of which explicitly allocated and constructed >> NUL-terminated strings (or worse: modified read-only buffers to insert >> NULs).
Also, I think there is nobody that modified read-only buffer. diffgrep_consume() does say "Yuck -- line ought to be const", but its "line" parameter is actually a non-const exactly for this yuckiness (iow, it knew what it was doing).
Perhaps like so?
regex: use regexec_buf()
The new regexec_buf() function operates on buffers with an explicitly
specified length, rather than NUL-terminated strings.
We need to use this function whenever the buffer we want to pass to
regexec(3) may have been mmap(2)ed (and is hence not NUL-terminated).
Note: the original motivation for this patch was to fix a bug where
`git diff -G <regex>` would crash. This patch converts more callers,
though, some of which allocated to construct NUL-terminated strings,
or worse, modified buffers to temporarily insert NULs while calling
regexec(3). By converting them to use regexec_buf() they have become
much cleaner.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>The patch text looked good to me.
Thanks.