Commit b74c76254a0262d7eca704ebdb9e3bbb1d6fecb2

Stefan Sperling 2018-05-20T12:51:27

make git_diff_object helpers error if both objects are NULL

diff --git a/lib/diff.c b/lib/diff.c
index f0adc78..6d77494 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -448,6 +448,9 @@ got_diff_objects_as_blobs(struct got_object *obj1, struct got_object *obj2,
 	const struct got_error *err;
 	struct got_blob_object *blob1 = NULL, *blob2 = NULL;
 
+	if (obj1 == NULL && obj2 == NULL)
+		return got_error(GOT_ERR_NO_OBJ);
+
 	if (obj1) {
 		err = got_object_blob_open(&blob1, repo, obj1, 8192);
 		if (err)
@@ -474,6 +477,9 @@ got_diff_objects_as_trees(struct got_object *obj1, struct got_object *obj2,
 	const struct got_error *err;
 	struct got_tree_object *tree1 = NULL, *tree2 = NULL;
 
+	if (obj1 == NULL && obj2 == NULL)
+		return got_error(GOT_ERR_NO_OBJ);
+
 	if (obj1) {
 		err = got_object_tree_open(&tree1, repo, obj1);
 		if (err)
@@ -501,6 +507,9 @@ got_diff_objects_as_commits(struct got_object *obj1, struct got_object *obj2,
 	struct got_commit_object *commit1 = NULL, *commit2 = NULL;
 	struct got_object *tree_obj1  = NULL, *tree_obj2 = NULL;
 
+	if (obj1 == NULL && obj2 == NULL)
+		return got_error(GOT_ERR_NO_OBJ);
+
 	if (obj1) {
 		err = got_object_commit_open(&commit1, repo, obj1);
 		if (err)