Skip to content

Commit 42d2ad5

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 86badd4 commit 42d2ad5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

line-log.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ static int process_diff_filepair(struct rev_info *rev,
10321032
struct range_set tmp;
10331033
struct diff_ranges diff;
10341034
mmfile_t file_parent, file_target;
1035+
char *parent_data_to_free = NULL;
10351036

10361037
assert(pair->two->path);
10371038
while (rg) {
@@ -1056,7 +1057,7 @@ static int process_diff_filepair(struct rev_info *rev,
10561057
file_parent.ptr = pair->one->data;
10571058
file_parent.size = pair->one->size;
10581059
} else {
1059-
file_parent.ptr = "";
1060+
file_parent.ptr = parent_data_to_free = xstrdup("");
10601061
file_parent.size = 0;
10611062
}
10621063

@@ -1075,6 +1076,7 @@ static int process_diff_filepair(struct rev_info *rev,
10751076

10761077
diff_ranges_release(&diff);
10771078

1079+
free(parent_data_to_free);
10781080
return ((*diff_out)->parent.nr > 0);
10791081
}
10801082

0 commit comments

Comments
 (0)