Commit 60f50a586ee410f07b141d9940434644c15c9faa

Stefan Sperling 2018-09-15T15:20:24

don't crash in got_diff_tree() if trees are empty

diff --git a/lib/diff.c b/lib/diff.c
index 5355fad..c412692 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -440,7 +440,7 @@ got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
 		const struct got_tree_entries *entries;
 		entries = got_object_tree_get_entries(tree1);
 		te1 = SIMPLEQ_FIRST(&entries->head);
-		if (asprintf(&l1, "%s%s%s", label1, label1[0] ? "/" : "",
+		if (te1 && asprintf(&l1, "%s%s%s", label1, label1[0] ? "/" : "",
 		    te1->name) == -1)
 			return got_error_from_errno();
 	}
@@ -448,7 +448,7 @@ got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
 		const struct got_tree_entries *entries;
 		entries = got_object_tree_get_entries(tree2);
 		te2 = SIMPLEQ_FIRST(&entries->head);
-		if (asprintf(&l2, "%s%s%s", label2, label2[0] ? "/" : "",
+		if (te2 && asprintf(&l2, "%s%s%s", label2, label2[0] ? "/" : "",
 		    te2->name) == -1)
 			return got_error_from_errno();
 	}