]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ll_union_merge(): pass name labels to ll_xdl_merge()
authorJeff King <peff@peff.net>
Thu, 10 Jun 2021 12:58:43 +0000 (08:58 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 11 Jun 2021 03:37:07 +0000 (12:37 +0900)
Since cd1d61c44f (make union merge an xdl merge favor, 2010-03-01), we
pass NULL to ll_xdl_merge() for the "name" labels of the ancestor, ours
and theirs buffers. We usually use these for annotating conflict markers
left in a file. For a union merge, these shouldn't matter; the point of
it is that we'd never leave conflict markers in the first place.

But there is one code path where we may dereference them: if the file
contents appear to be binary, ll_binary_merge() will give up and pass
them to warning() to generate a message for the user (that was true even
when cd1d61c44f was written, though the warning was in ll_xdl_merge()
back then).

That can result in a segfault, though on many systems (including glibc),
the printf routines will helpfully just say "(null)" instead. We can
extend our binary-union test in t6406 to check stderr, which catches the
problem on all systems.

This also fixes a warning from "gcc -O3". Unlike lower optimization
levels, it inlines enough to see that the NULL can make it to warning()
and complains:

  In function ‘ll_binary_merge’,
      inlined from ‘ll_xdl_merge’ at ll-merge.c:115:10,
      inlined from ‘ll_union_merge’ at ll-merge.c:151:9:
  ll-merge.c:74:4: warning: ‘%s’ directive argument is null [-Wformat-overflow=]
     74 |    warning("Cannot merge binary files: %s (%s vs. %s)",
        |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     75 |     path, name1, name2);
        |     ~~~~~~~~~~~~~~~~~~~

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ll-merge.c
t/t6406-merge-attr.sh

index 145deb12fac6e54890b9403d068238c52980e69e..0ee34d8a0141c57e3e8a3a4c071b97fdad95acc1 100644 (file)
@@ -151,7 +151,7 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
        o = *opts;
        o.variant = XDL_MERGE_FAVOR_UNION;
        return ll_xdl_merge(drv_unused, result, path_unused,
-                           orig, NULL, src1, NULL, src2, NULL,
+                           orig, orig_name, src1, name1, src2, name2,
                            &o, marker_size);
 }
 
index c1c458d9339b8e5700b92bb49034c0404ec7e47c..849464583713c40859d2473d2a4075367b1e4c09 100755 (executable)
@@ -221,7 +221,8 @@ test_expect_success 'binary files with union attribute' '
        printf "two\0" >bin.txt &&
        git commit -am two &&
 
-       test_must_fail git merge bin-main
+       test_must_fail git merge bin-main 2>stderr &&
+       grep -i "warning.*cannot merge.*HEAD vs. bin-main" stderr
 '
 
 test_done