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>
This commit is contained in:
parent
e010a41216
commit
12878c8351
16
contrib/coccinelle/hashmap.cocci
Normal file
16
contrib/coccinelle/hashmap.cocci
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
@ hashmap_entry_init_usage @
|
||||||
|
expression E;
|
||||||
|
struct hashmap_entry HME;
|
||||||
|
@@
|
||||||
|
- HME.hash = E;
|
||||||
|
+ hashmap_entry_init(&HME, E);
|
||||||
|
|
||||||
|
@@
|
||||||
|
identifier f !~ "^hashmap_entry_init$";
|
||||||
|
expression E;
|
||||||
|
struct hashmap_entry *HMEP;
|
||||||
|
@@
|
||||||
|
f(...) {<...
|
||||||
|
- HMEP->hash = E;
|
||||||
|
+ hashmap_entry_init(HMEP, E);
|
||||||
|
...>}
|
Loading…
Reference in New Issue
Block a user