]> git.ipfire.org Git - thirdparty/git.git/commitdiff
line-log: stop assigning string constant to file parent buffer
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Jun 2024 06:38:11 +0000 (08:38 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 17:30:50 +0000 (10:30 -0700)
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>
line-log.c

index 8ff6ccb77241fd249f58827ecc1add65356648a4..bd3e663c24275e375282e5376f9a653c74253343 100644 (file)
@@ -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);
 }