summaryrefslogtreecommitdiff
path: root/src/diff_output.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-10-25 11:12:56 -0700
committerRussell Belfer <rb@github.com>2012-10-25 11:12:56 -0700
commit3943dc78a5c67c1db367c4e13a79884ef72f7f3b (patch)
treeda2a9793b7b83265fdaf32f1e769a5051de23056 /src/diff_output.c
parent93cf7bb8e26a04d9bd4197c1b938cee352023f63 (diff)
downloadlibgit2-3943dc78a5c67c1db367c4e13a79884ef72f7f3b.tar.gz
Check errors while generating diff patch string
Diffstat (limited to 'src/diff_output.c')
-rw-r--r--src/diff_output.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/diff_output.c b/src/diff_output.c
index 511e9318b..495de251b 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -1514,8 +1514,7 @@ static int print_to_buffer_cb(
GIT_UNUSED(delta);
GIT_UNUSED(range);
GIT_UNUSED(line_origin);
- git_buf_put(output, content, content_len);
- return 0;
+ return git_buf_put(output, content, content_len);
}
int git_diff_patch_to_str(
@@ -1527,6 +1526,8 @@ int git_diff_patch_to_str(
diff_print_info pi;
size_t h, l;
+ assert(string && patch);
+
pi.diff = patch->diff;
pi.print_cb = print_to_buffer_cb;
pi.cb_data = &output;
@@ -1534,13 +1535,13 @@ int git_diff_patch_to_str(
error = print_patch_file(&pi, patch->delta, 0);
- for (h = 0; h < patch->hunks_size; ++h) {
+ for (h = 0; h < patch->hunks_size && !error; ++h) {
diff_patch_hunk *hunk = &patch->hunks[h];
error = print_patch_hunk(&pi, patch->delta,
&hunk->range, hunk->header, hunk->header_len);
- for (l = 0; l < hunk->line_count; ++l) {
+ for (l = 0; l < hunk->line_count && !error; ++l) {
diff_patch_line *line = &patch->lines[hunk->line_start + l];
error = print_patch_line(
@@ -1549,6 +1550,12 @@ int git_diff_patch_to_str(
}
}
+ /* GIT_EUSER means git_buf_put in print_to_buffer_cb returned -1,
+ * meaning a memory allocation failure, so just map to -1...
+ */
+ if (error == GIT_EUSER)
+ error = -1;
+
git_buf_free(&temp);
*string = git_buf_detach(&output);