diff options
Diffstat (limited to 'contrib/coccinelle')
-rw-r--r-- | contrib/coccinelle/array.cocci | 39 | ||||
-rw-r--r-- | contrib/coccinelle/commit.cocci | 28 | ||||
-rw-r--r-- | contrib/coccinelle/free.cocci | 13 | ||||
-rw-r--r-- | contrib/coccinelle/strbuf.cocci | 26 | ||||
-rw-r--r-- | contrib/coccinelle/swap.cocci | 28 | ||||
-rw-r--r-- | contrib/coccinelle/xstrdup_or_null.cocci | 6 |
6 files changed, 120 insertions, 20 deletions
diff --git a/contrib/coccinelle/array.cocci b/contrib/coccinelle/array.cocci index 2d7f25d99f..01586821dc 100644 --- a/contrib/coccinelle/array.cocci +++ b/contrib/coccinelle/array.cocci @@ -4,7 +4,7 @@ T *dst; T *src; expression n; @@ -- memcpy(dst, src, n * sizeof(*dst)); +- memcpy(dst, src, (n) * sizeof(*dst)); + COPY_ARRAY(dst, src, n); @@ @@ -13,7 +13,7 @@ T *dst; T *src; expression n; @@ -- memcpy(dst, src, n * sizeof(*src)); +- memcpy(dst, src, (n) * sizeof(*src)); + COPY_ARRAY(dst, src, n); @@ @@ -22,5 +22,38 @@ T *dst; T *src; expression n; @@ -- memcpy(dst, src, n * sizeof(T)); +- memcpy(dst, src, (n) * sizeof(T)); + COPY_ARRAY(dst, src, n); + +@@ +type T; +T *dst; +T *src; +expression n; +@@ +( +- memmove(dst, src, (n) * sizeof(*dst)); ++ MOVE_ARRAY(dst, src, n); +| +- memmove(dst, src, (n) * sizeof(*src)); ++ MOVE_ARRAY(dst, src, n); +| +- memmove(dst, src, (n) * sizeof(T)); ++ MOVE_ARRAY(dst, src, n); +) + +@@ +type T; +T *ptr; +expression n; +@@ +- ptr = xmalloc((n) * sizeof(*ptr)); ++ ALLOC_ARRAY(ptr, n); + +@@ +type T; +T *ptr; +expression n; +@@ +- ptr = xmalloc((n) * sizeof(T)); ++ ALLOC_ARRAY(ptr, n); diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci new file mode 100644 index 0000000000..a7e9215ffc --- /dev/null +++ b/contrib/coccinelle/commit.cocci @@ -0,0 +1,28 @@ +@@ +expression c; +@@ +- &c->maybe_tree->object.oid ++ get_commit_tree_oid(c) + +@@ +expression c; +@@ +- c->maybe_tree->object.oid.hash ++ get_commit_tree_oid(c)->hash + +// These excluded functions must access c->maybe_tree direcly. +@@ +identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph|load_tree_for_commit)$"; +expression c; +@@ + f(...) {... +- c->maybe_tree ++ get_commit_tree(c) + ...} + +@@ +expression c; +expression s; +@@ +- get_commit_tree(c) = s ++ c->maybe_tree = s diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci index e28213161a..4490069df9 100644 --- a/contrib/coccinelle/free.cocci +++ b/contrib/coccinelle/free.cocci @@ -3,3 +3,16 @@ expression E; @@ - if (E) free(E); + +@@ +expression E; +@@ +- if (!E) + free(E); + +@@ +expression E; +@@ +- free(E); ++ FREE_AND_NULL(E); +- E = NULL; diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci index 63995f22ff..e34eada1ad 100644 --- a/contrib/coccinelle/strbuf.cocci +++ b/contrib/coccinelle/strbuf.cocci @@ -1,21 +1,6 @@ @ strbuf_addf_with_format_only @ expression E; -constant fmt; -@@ - strbuf_addf(E, -( - fmt -| - _(fmt) -) - ); - -@ script:python @ -fmt << strbuf_addf_with_format_only.fmt; -@@ -cocci.include_match("%" not in fmt) - -@ extends strbuf_addf_with_format_only @ +constant fmt !~ "%"; @@ - strbuf_addf + strbuf_addstr @@ -29,8 +14,9 @@ cocci.include_match("%" not in fmt) @@ expression E1, E2; +format F =~ "s"; @@ -- strbuf_addf(E1, "%s", E2); +- strbuf_addf(E1, "%@F@", E2); + strbuf_addstr(E1, E2); @@ @@ -38,3 +24,9 @@ expression E1, E2, E3; @@ - strbuf_addstr(E1, find_unique_abbrev(E2, E3)); + strbuf_add_unique_abbrev(E1, E2, E3); + +@@ +expression E1, E2; +@@ +- strbuf_addstr(E1, real_path(E2)); ++ strbuf_add_real_path(E1, E2); diff --git a/contrib/coccinelle/swap.cocci b/contrib/coccinelle/swap.cocci new file mode 100644 index 0000000000..a0934d1fda --- /dev/null +++ b/contrib/coccinelle/swap.cocci @@ -0,0 +1,28 @@ +@ swap_with_declaration @ +type T; +identifier tmp; +T a, b; +@@ +- T tmp = a; ++ T tmp; ++ tmp = a; + a = b; + b = tmp; + +@ swap @ +type T; +T tmp, a, b; +@@ +- tmp = a; +- a = b; +- b = tmp; ++ SWAP(a, b); + +@ extends swap @ +identifier unused; +@@ + { + ... +- T unused; + ... when != unused + } diff --git a/contrib/coccinelle/xstrdup_or_null.cocci b/contrib/coccinelle/xstrdup_or_null.cocci index 3fceef132b..8e05d1ca4b 100644 --- a/contrib/coccinelle/xstrdup_or_null.cocci +++ b/contrib/coccinelle/xstrdup_or_null.cocci @@ -5,3 +5,9 @@ expression V; - if (E) - V = xstrdup(E); + V = xstrdup_or_null(E); + +@@ +expression E; +@@ +- xstrdup(absolute_path(E)) ++ absolute_pathdup(E) |