coccicheck: detect hashmap_entry.hash assignment

Assigning hashmap_entry.hash manually leaves hashmap_entry.next uninitialized, which can be dangerous once the hashmap_entry is inserted into a hashmap. Detect those assignments and use hashmap_entry_init, instead. Signed-off-by: Eric Wong <e@80x24.org> Reviewed-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Wong committed Oct 6, 2019 at 23:30 UTC 12878c83516e3b82f31a20f1b5431b7ff607a8db
1 file changed +16
contrib/coccinelle/hashmap.cocci new
+16
@@ -0,0 +1,16 @@
1 +@ hashmap_entry_init_usage @
2 +expression E;
3 +struct hashmap_entry HME;
4 +@@
5 +- HME.hash = E;
6 ++ hashmap_entry_init(&HME, E);
7 +
8 +@@
9 +identifier f !~ "^hashmap_entry_init$";
10 +expression E;
11 +struct hashmap_entry *HMEP;
12 +@@
13 + f(...) {<...
14 +- HMEP->hash = E;
15 ++ hashmap_entry_init(HMEP, E);
16 + ...>}