Skip to content

Commit 12878c8

Browse files
Eric Wonggitster
authored andcommitted
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 <[email protected]> Reviewed-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e010a41 commit 12878c8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

contrib/coccinelle/hashmap.cocci

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
...>}

0 commit comments

Comments
 (0)