]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff: use hashmap_entry_init on moved_entry.ent
authorEric Wong <e@80x24.org>
Sun, 6 Oct 2019 23:30:24 +0000 (23:30 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Oct 2019 01:20:09 +0000 (10:20 +0900)
Otherwise, the hashmap_entry.next field appears to remain
uninitialized, which can lead to problems when
add_lines_to_move_detection calls hashmap_add.

I found this through manual inspection when converting
hashmap_add callers to take "struct hashmap_entry *".

Signed-off-by: Eric Wong <e@80x24.org>
Reviewed-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c

diff --git a/diff.c b/diff.c
index efe42b341ae15ebceb1e216518ab3a542be361dc..02491ee68481e99fb178cac93ab0631b12dbca8e 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -964,8 +964,9 @@ static struct moved_entry *prepare_entry(struct diff_options *o,
        struct moved_entry *ret = xmalloc(sizeof(*ret));
        struct emitted_diff_symbol *l = &o->emitted_symbols->buf[line_no];
        unsigned flags = o->color_moved_ws_handling & XDF_WHITESPACE_FLAGS;
+       unsigned int hash = xdiff_hash_string(l->line, l->len, flags);
 
-       ret->ent.hash = xdiff_hash_string(l->line, l->len, flags);
+       hashmap_entry_init(&ret->ent, hash);
        ret->es = l;
        ret->next_line = NULL;