summaryrefslogtreecommitdiff
path: root/contrib/coccinelle
diff options
context:
space:
mode:
authorLibravatar René Scharfe <l.s.r@web.de>2021-03-06 12:26:19 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-03-08 09:45:04 -0800
commit241b5d3ebeea21b70a74fdc8c74e73f7ed829cb1 (patch)
tree2912c1f5896fb1356a4ba09fa48129e1a5dd310f /contrib/coccinelle
parentMerge branch 'tb/ci-run-cocci-with-18.04' into maint (diff)
downloadtgif-241b5d3ebeea21b70a74fdc8c74e73f7ed829cb1.tar.xz
fix xcalloc() argument order
Pass the number of elements first and ther size second, as expected by xcalloc(). Provide a semantic patch, which was actually used to generate the rest of this patch. The semantic patch would generate flip-flop diffs if both arguments are sizeofs. We don't have such a case, and it's hard to imagine the usefulness of such an allocation. If it ever occurs then we could deal with it by duplicating the rule in the semantic patch to make it cancel itself out, or we could change the code to use CALLOC_ARRAY. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/coccinelle')
-rw-r--r--contrib/coccinelle/xcalloc.cocci10
1 files changed, 10 insertions, 0 deletions
diff --git a/contrib/coccinelle/xcalloc.cocci b/contrib/coccinelle/xcalloc.cocci
new file mode 100644
index 0000000000..c291011607
--- /dev/null
+++ b/contrib/coccinelle/xcalloc.cocci
@@ -0,0 +1,10 @@
+@@
+type T;
+T *ptr;
+expression n;
+@@
+ xcalloc(
++ n,
+ \( sizeof(T) \| sizeof(*ptr) \)
+- , n
+ )