Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-07-06 03:59:38 +0400
committerRussell Belfer <rb@github.com>2013-07-06 03:59:38 +0400
commita5f9b5f8d8c2dbcd1bec92065e5df7bae76d3c7c (patch)
treeba8962145082f91aa6a7473869457e741ba38c95 /src/diff_driver.c
parent82cb8e236a07d8684c53aa8ee5b1c6195f788371 (diff)
Diff hunk context off by one on long lines
The diff hunk context string that is returned to xdiff need not be NUL terminated because the xdiff code just copies the number of bytes that you report directly into the output. There was an off by one in the diff driver code when the header context was longer than the output buffer size, the output buffer length included the NUL byte which was copied into the hunk header. Fixes #1710
Diffstat (limited to 'src/diff_driver.c')
-rw-r--r--src/diff_driver.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/diff_driver.c b/src/diff_driver.c
index 469be0d14..77b0e9f3e 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -373,10 +373,11 @@ static long diff_context_find(
!ctxt->match_line(ctxt->driver, ctxt->line.ptr, ctxt->line.size))
return -1;
- git_buf_truncate(&ctxt->line, (size_t)out_size);
- git_buf_copy_cstr(out, (size_t)out_size, &ctxt->line);
+ if (out_size > (long)ctxt->line.size)
+ out_size = ctxt->line.size;
+ memcpy(out, ctxt->line.ptr, (size_t)out_size);
- return (long)ctxt->line.size;
+ return out_size;
}
void git_diff_find_context_init(