summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2016-09-21 18:24:14 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-09-21 20:56:15 (GMT)
commitb7d36ffca02c23f545d6e098d78180e6e72dfd8d (patch)
treeee20baae52d14d948c581efdbf30aff6fa2ee62e /diff.c
parent2f8952250a84313b74f96abb7b035874854cf202 (diff)
downloadgit-b7d36ffca02c23f545d6e098d78180e6e72dfd8d.zip
git-b7d36ffca02c23f545d6e098d78180e6e72dfd8d.tar.gz
git-b7d36ffca02c23f545d6e098d78180e6e72dfd8d.tar.bz2
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(), the code has become much cleaner. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/diff.c b/diff.c
index 059123c..f77324e 100644
--- a/diff.c
+++ b/diff.c
@@ -941,7 +941,8 @@ static int find_word_boundaries(mmfile_t *buffer, regex_t *word_regex,
{
if (word_regex && *begin < buffer->size) {
regmatch_t match[1];
- if (!regexec(word_regex, buffer->ptr + *begin, 1, match, 0)) {
+ if (!regexec_buf(word_regex, buffer->ptr + *begin,
+ buffer->size - *begin, 1, match, 0)) {
char *p = memchr(buffer->ptr + *begin + match[0].rm_so,
'\n', match[0].rm_eo - match[0].rm_so);
*end = p ? p - buffer->ptr : match[0].rm_eo + *begin;