summaryrefslogtreecommitdiff
path: root/contrib/coccinelle
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-10-06 23:30:25 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-10-07 01:20:09 (GMT)
commit12878c83516e3b82f31a20f1b5431b7ff607a8db (patch)
tree074069d3c740b5745e2bbb3aece81177ad742acf /contrib/coccinelle
parente010a41216efd85eacc4c0711ea405de4fb20526 (diff)
downloadgit-12878c83516e3b82f31a20f1b5431b7ff607a8db.zip
git-12878c83516e3b82f31a20f1b5431b7ff607a8db.tar.gz
git-12878c83516e3b82f31a20f1b5431b7ff607a8db.tar.bz2
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>
Diffstat (limited to 'contrib/coccinelle')
-rw-r--r--contrib/coccinelle/hashmap.cocci16
1 files changed, 16 insertions, 0 deletions
diff --git a/contrib/coccinelle/hashmap.cocci b/contrib/coccinelle/hashmap.cocci
new file mode 100644
index 0000000..d69e120
--- /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);
+ ...>}