[01/11] diff: use hashmap_entry_init on moved_entry.ent
diff mbox series

Message ID 20190826024332.3403-2-e@80x24.org
State New
Headers show
Series
  • [01/11] diff: use hashmap_entry_init on moved_entry.ent
Related show

Commit Message

Eric Wong Aug. 26, 2019, 2:43 a.m. UTC
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>
---
 diff.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Derrick Stolee Aug. 27, 2019, 1:31 p.m. UTC | #1
On 8/25/2019 10:43 PM, Eric Wong wrote:
> 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>
> ---
>  diff.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/diff.c b/diff.c
> index efe42b341a..02491ee684 100644
> --- 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);

I've typically seen these hashmap_entry_init() calls include the
hash function in-line instead of saving to a variable. But, this
looks fine and is obviously correct.

Thanks,
-Stolee

Patch
diff mbox series

diff --git a/diff.c b/diff.c
index efe42b341a..02491ee684 100644
--- 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;