Commit bea5fd9f44857ddae2addd543ac5cf444c1280ff

Patrick Steinhardt 2020-06-15T13:26:18

diff_print: do not call abort(3P) Calling abort(3P) in a library is rather rude and shouldn't happen, as we effectively prohibit any corrective actions made by the application linking to it. We thus shouldn't call it at all, but instead use our new `GIT_ASSERT` macros. Remove the call to abort(3P) in case a diff delta has an unexpected type to fix this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/src/diff_print.c b/src/diff_print.c
index 8f378d9..afe2efa 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -351,12 +351,11 @@ static int diff_delta_format_similarity_header(
 		goto done;
 	}
 
+	GIT_ASSERT(delta->status == GIT_DELTA_RENAMED || delta->status == GIT_DELTA_COPIED);
 	if (delta->status == GIT_DELTA_RENAMED)
 		type = "rename";
-	else if (delta->status == GIT_DELTA_COPIED)
-		type = "copy";
 	else
-		abort();
+		type = "copy";
 
 	if ((error = git_buf_puts(&old_path, delta->old_file.path)) < 0 ||
 	    (error = git_buf_puts(&new_path, delta->new_file.path)) < 0 ||