From: Eric Wong Date: Sun, 6 Oct 2019 23:30:25 +0000 (+0000) Subject: coccicheck: detect hashmap_entry.hash assignment X-Git-Tag: v2.24.0-rc0~21^2~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=12878c83516e3b82f31a20f1b5431b7ff607a8db;p=thirdparty%2Fgit.git 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 Reviewed-by: Derrick Stolee Signed-off-by: Junio C Hamano --- diff --git a/contrib/coccinelle/hashmap.cocci b/contrib/coccinelle/hashmap.cocci new file mode 100644 index 0000000000..d69e120ccf --- /dev/null +++ b/contrib/coccinelle/hashmap.cocci @@ -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); + ...>}