From: Junio C Hamano Date: Wed, 21 Sep 2016 20:09:35 GMT Subject: Re: [PATCH v4 3/3] regex: use regexec_buf() Message-ID: In-Reply-To: Junio C Hamano writes: > Johannes Schindelin 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 ` 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 ` 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 Signed-off-by: Junio C Hamano The patch text looked good to me. Thanks.