Commit a00719e9ec7fca4511eb77a8aee31bd098f52c68

Stefan Sperling 2022-06-17T11:01:26

fix a segfault in tog diff The f1 tempfile must always be created. Even if the initial diff has no objects on the left side, the view can be switched to a different diff which does have objects on both sides. When that happened, tog crashed. (To reproduce: open tog in got.git, hit G, hit Enter, hit <)

diff --git a/tog/tog.c b/tog/tog.c
index 3a68d82..8782d22 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -3830,11 +3830,6 @@ open_diff_view(struct tog_view *view, struct got_object_id *id1,
 		s->id1 = got_object_id_dup(id1);
 		if (s->id1 == NULL)
 			return got_error_from_errno("got_object_id_dup");
-		s->f1 = got_opentemp();
-		if (s->f1 == NULL) {
-			err = got_error_from_errno("got_opentemp");
-			goto done;
-		}
 	} else
 		s->id1 = NULL;
 
@@ -3844,6 +3839,12 @@ open_diff_view(struct tog_view *view, struct got_object_id *id1,
 		goto done;
 	}
 
+	s->f1 = got_opentemp();
+	if (s->f1 == NULL) {
+		err = got_error_from_errno("got_opentemp");
+		goto done;
+	}
+
 	s->f2 = got_opentemp();
 	if (s->f2 == NULL) {
 		err = got_error_from_errno("got_opentemp");