Junio C Hamano <gitster@xxxxxxxxx> writes: > Johannes Schindelin <johannes.schindelin@xxxxxx> 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@xxxxxx> Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> The patch text looked good to me. Thanks.