diff: allow passing NULL to diff_free_filespec_data()
Commit 3aef54e8b8 ("diff: munmap() file contents before running external diff") introduced calls to diff_free_filespec_data in run_external_diff, which may pass NULL pointers. Fix this and prevent any such bugs in the future by making `diff_free_filespec_data(NULL)` a no-op. Fixes: 3aef54e8b8 ("diff: munmap() file contents before running external diff") Signed-off-by: Jinoh Kang <luke1337@theori.io> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jinoh Kang committed
Nov 6, 2020 at 17:14 UTC
246959346f3407cb047c3d46ed9c44da84bd0b29
2 files changed
+26
diff.c
+3
@@ -4111,6 +4111,9 @@ void diff_free_filespec_blob(struct diff_filespec *s)
4111
4112
void diff_free_filespec_data(struct diff_filespec *s)
4113
{
4114
+ if (!s)
4115
+ return;
4116
+
4117
diff_free_filespec_blob(s);
4118
FREE_AND_NULL(s->cnt_data);
4119
}
t/t7800-difftool.sh
+23
@@ -728,6 +728,29 @@ test_expect_success 'add -N and difftool -d' '
728
git difftool --dir-diff --extcmd ls
729
'
730
731
+test_expect_success 'difftool --cached with unmerged files' '
732
+ test_when_finished git reset --hard &&
733
+ echo base >file &&
734
+ git add file &&
735
+ git commit -m base &&
736
+ git checkout -B conflict-a &&
737
+ git checkout -B conflict-b &&
738
+ git checkout conflict-a &&
739
+ echo conflict-a >>file &&
740
+ git add file &&
741
+ git commit -m conflict-a &&
742
+ git checkout conflict-b &&
743
+ echo conflict-b >>file &&
744
+ git add file &&
745
+ git commit -m conflict-b &&
746
+ git checkout master &&
747
+ git merge conflict-a &&
748
+ test_must_fail git merge conflict-b &&
749
+ : >expect &&
750
+ git difftool --cached --no-prompt >actual &&
751
+ test_cmp expect actual
752
+'
753
+
754
test_expect_success 'outside worktree' '
755
echo 1 >1 &&
756
echo 2 >2 &&