[PATCH v5 08/27] line-log: stop assigning string constant to file parent buffer
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Jun 6, 2024, 10:28 UTC
- Message-ID
- <ac164651a325476ecf041641c11785ac8c0c1501.1717667854.git.ps@pks.im>
- In-Reply-To
- <cover.1717667854.git.ps@pks.im>
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> --- line-log.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/line-log.c b/line-log.c index 8ff6ccb772..bd3e663c24 100644 --- a/line-log.c +++ b/line-log.c @@ -1032,6 +1032,7 @@ static int process_diff_filepair(struct rev_info *rev, struct range_set tmp; struct diff_ranges diff; mmfile_t file_parent, file_target; + char *parent_data_to_free = NULL; assert(pair->two->path); while (rg) { @@ -1056,7 +1057,7 @@ static int process_diff_filepair(struct rev_info *rev, file_parent.ptr = pair->one->data; file_parent.size = pair->one->size; } else { - file_parent.ptr = ""; + file_parent.ptr = parent_data_to_free = xstrdup(""); file_parent.size = 0; } @@ -1075,6 +1076,7 @@ static int process_diff_filepair(struct rev_info *rev, diff_ranges_release(&diff); + free(parent_data_to_free); return ((*diff_out)->parent.nr > 0); }
-- 2.45.2.409.g7b0defb391.dirty