Commit fb311a665c429d9d55ff03c54d894a847aed7ed2

Stefan Sperling 2018-07-10T22:00:22

don't crash in tog blame -> diff if commit has no parent

diff --git a/tog/tog.c b/tog/tog.c
index 083e46a..5574c90 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1411,15 +1411,20 @@ show_blame_view(const char *path, struct got_object_id *commit_id,
 				if (err)
 					goto done;
 				pid = SIMPLEQ_FIRST(&commit->parent_ids);
-				err = got_object_open(&obj1, repo, pid->id);
+				if (pid) {
+					err = got_object_open(&obj1, repo,
+					    pid->id);
+					if (err)
+						goto done;
+				}
 				got_object_commit_close(commit);
 				commit = NULL;
-				if (err)
-					goto done;
 				err = show_diff_view(obj1, obj2, repo);
-				got_object_close(obj1);
+				if (obj1) {
+					got_object_close(obj1);
+					obj1 = NULL;
+				}
 				got_object_close(obj2);
-				obj1 = NULL;
 				obj2 = NULL;
 				show_panel(tog_blame_view.panel);
 				if (err)