line-log: stop assigning string constant to file parent buffer

Stop assigning a string constant to the file parent buffer and instead assign an allocated string. While the code is fine in practice, it will break once we compile with `-Wwrite-strings`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jun 7, 2024 at 08:38 UTC 42d2ad55566013535c16b80fc2d445da93cceed3
1 file changed +3 -1
line-log.c
+3 -1
@@ -1032,6 +1032,7 @@ static int process_diff_filepair(struct rev_info *rev,
1032 struct range_set tmp;
1033 struct diff_ranges diff;
1034 mmfile_t file_parent, file_target;
1035 + char *parent_data_to_free = NULL;
1036
1037 assert(pair->two->path);
1038 while (rg) {
@@ -1056,7 +1057,7 @@ static int process_diff_filepair(struct rev_info *rev,
1057 file_parent.ptr = pair->one->data;
1058 file_parent.size = pair->one->size;
1059 } else {
1059 - file_parent.ptr = "";
1060 + file_parent.ptr = parent_data_to_free = xstrdup("");
1061 file_parent.size = 0;
1062 }
1063
@@ -1075,6 +1076,7 @@ static int process_diff_filepair(struct rev_info *rev,
1076
1077 diff_ranges_release(&diff);
1078
1079 + free(parent_data_to_free);
1080 return ((*diff_out)->parent.nr > 0);
1081 }
1082