Skip to content

Commit 2469593

Browse files
jinohkang-theorigitster
authored andcommitted
diff: allow passing NULL to diff_free_filespec_data()
Commit 3aef54e ("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: 3aef54e ("diff: munmap() file contents before running external diff") Signed-off-by: Jinoh Kang <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 898f807 commit 2469593

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

diff.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4111,6 +4111,9 @@ void diff_free_filespec_blob(struct diff_filespec *s)
41114111

41124112
void diff_free_filespec_data(struct diff_filespec *s)
41134113
{
4114+
if (!s)
4115+
return;
4116+
41144117
diff_free_filespec_blob(s);
41154118
FREE_AND_NULL(s->cnt_data);
41164119
}

t/t7800-difftool.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,29 @@ test_expect_success 'add -N and difftool -d' '
728728
git difftool --dir-diff --extcmd ls
729729
'
730730

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+
731754
test_expect_success 'outside worktree' '
732755
echo 1 >1 &&
733756
echo 2 >2 &&

0 commit comments

Comments
 (0)