From 76d156766fc9364ed2ce1b07f0867cbbdc5932f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 15 Sep 2016 20:30:52 +0200 Subject: contrib/coccinelle: fix semantic patch for oid_to_hex_r() Both sha1_to_hex_r() and oid_to_hex_r() take two parameters, so use two expressions in the semantic patch for transforming calls of the former to the latter one. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- contrib/coccinelle/object_id.cocci | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'contrib') diff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci index 8ccdbb5666..0307624a03 100644 --- a/contrib/coccinelle/object_id.cocci +++ b/contrib/coccinelle/object_id.cocci @@ -23,16 +23,16 @@ expression E1; + oid_to_hex(E1) @@ -expression E1; +expression E1, E2; @@ -- sha1_to_hex_r(E1.hash) -+ oid_to_hex_r(&E1) +- sha1_to_hex_r(E1, E2.hash) ++ oid_to_hex_r(E1, &E2) @@ -expression E1; +expression E1, E2; @@ -- sha1_to_hex_r(E1->hash) -+ oid_to_hex_r(E1) +- sha1_to_hex_r(E1, E2->hash) ++ oid_to_hex_r(E1, E2) @@ expression E1; -- cgit v1.2.3 From a22ae753cb297cb8a1e3ae950ae4415190cd51d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 15 Sep 2016 20:31:00 +0200 Subject: use strbuf_addstr() for adding constant strings to a strbuf, part 2 Replace uses of strbuf_addf() for adding strings with more lightweight strbuf_addstr() calls. This makes the intent clearer and avoids potential issues with printf format specifiers. 02962d36845b89145cd69f8bc65e015d78ae3434 already converted six cases, this patch covers eleven more. A semantic patch for Coccinelle is included for easier checking for new cases that might be introduced in the future. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- contrib/coccinelle/strbuf.cocci | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 contrib/coccinelle/strbuf.cocci (limited to 'contrib') diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci new file mode 100644 index 0000000000..7932d48cdf --- /dev/null +++ b/contrib/coccinelle/strbuf.cocci @@ -0,0 +1,5 @@ +@@ +expression E1, E2; +@@ +- strbuf_addf(E1, E2); ++ strbuf_addstr(E1, E2); -- cgit v1.2.3 From 7f2817daef616e764afaaf302f85beb7a13e56dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 27 Sep 2016 22:12:33 +0200 Subject: gitignore: ignore output files of coccicheck make target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Helped-by: Jakub Narębski Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- contrib/coccinelle/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 contrib/coccinelle/.gitignore (limited to 'contrib') diff --git a/contrib/coccinelle/.gitignore b/contrib/coccinelle/.gitignore new file mode 100644 index 0000000000..d3f29646dc --- /dev/null +++ b/contrib/coccinelle/.gitignore @@ -0,0 +1 @@ +*.patch* -- cgit v1.2.3 From 92d52fab3af8b1d5231285ac13b364f008d1a886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 27 Sep 2016 21:08:21 +0200 Subject: use strbuf_addstr() instead of strbuf_addf() with "%s", part 2 Replace uses of strbuf_addf() for adding strings with more lightweight strbuf_addstr() calls. This is shorter and makes the intent clearer. bc57b9c0cc5a123365a922fa1831177e3fd607ed already converted three cases, this patch covers two more. A semantic patch for Coccinelle is included for easier checking for new cases that might be introduced in the future. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- contrib/coccinelle/strbuf.cocci | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'contrib') diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci index 7932d48cdf..4b7553f833 100644 --- a/contrib/coccinelle/strbuf.cocci +++ b/contrib/coccinelle/strbuf.cocci @@ -3,3 +3,9 @@ expression E1, E2; @@ - strbuf_addf(E1, E2); + strbuf_addstr(E1, E2); + +@@ +expression E1, E2; +@@ +- strbuf_addf(E1, "%s", E2); ++ strbuf_addstr(E1, E2); -- cgit v1.2.3 From f937d78553ce22505543580ae7958d9f5ffeeb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 27 Sep 2016 21:11:58 +0200 Subject: use strbuf_add_unique_abbrev() for adding short hashes, part 2 Call strbuf_add_unique_abbrev() to add abbreviated hashes to strbufs instead of taking detours through find_unique_abbrev() and its static buffer. This is shorter and a bit more efficient. 1eb47f167d65d1d305b9c196a1bb40eb96117cb1 already converted six cases, this patch covers three more. A semantic patch for Coccinelle is included for easier checking for new cases that might be introduced in the future. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- contrib/coccinelle/strbuf.cocci | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'contrib') diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci index 4b7553f833..1e242983cf 100644 --- a/contrib/coccinelle/strbuf.cocci +++ b/contrib/coccinelle/strbuf.cocci @@ -9,3 +9,9 @@ expression E1, E2; @@ - strbuf_addf(E1, "%s", E2); + strbuf_addstr(E1, E2); + +@@ +expression E1, E2, E3; +@@ +- strbuf_addstr(E1, find_unique_abbrev(E2, E3)); ++ strbuf_add_unique_abbrev(E1, E2, E3); -- cgit v1.2.3 From 353d84c537485500989b190c5af93ad224264e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Mon, 3 Oct 2016 00:58:21 +0200 Subject: coccicheck: make transformation for strbuf_addf(sb, "...") more precise We can replace strbuf_addf() calls that just add a simple string with calls to strbuf_addstr() to make the intent clearer. We need to be careful if that string contains printf format specifications like %%, though, as a simple replacement would change the output. Add checks to the semantic patch to make sure we only perform the transformation if the second argument is a string constant (possibly translated) that doesn't contain any percent signs. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- contrib/coccinelle/strbuf.cocci | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'contrib') diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci index 1e242983cf..63995f22ff 100644 --- a/contrib/coccinelle/strbuf.cocci +++ b/contrib/coccinelle/strbuf.cocci @@ -1,8 +1,31 @@ +@ strbuf_addf_with_format_only @ +expression E; +constant fmt; @@ -expression E1, E2; + strbuf_addf(E, +( + fmt +| + _(fmt) +) + ); + +@ script:python @ +fmt << strbuf_addf_with_format_only.fmt; @@ -- strbuf_addf(E1, E2); -+ strbuf_addstr(E1, E2); +cocci.include_match("%" not in fmt) + +@ extends strbuf_addf_with_format_only @ +@@ +- strbuf_addf ++ strbuf_addstr + (E, +( + fmt +| + _(fmt) +) + ); @@ expression E1, E2; -- cgit v1.2.3 From 39ea59a2570547166834ceeff9ae0c0c05748f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 8 Oct 2016 16:14:57 +0200 Subject: remove unnecessary NULL check before free(3) free(3) handles NULL pointers just fine. Add a semantic patch for removing unnecessary NULL checks before calling this function, and apply it on the code base. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- contrib/coccinelle/free.cocci | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 contrib/coccinelle/free.cocci (limited to 'contrib') diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci new file mode 100644 index 0000000000..e28213161a --- /dev/null +++ b/contrib/coccinelle/free.cocci @@ -0,0 +1,5 @@ +@@ +expression E; +@@ +- if (E) + free(E); -- cgit v1.2.3