Add Coccinelle usage: one for blacklisting, one for patch collection

This is inspired by the [Coccinelle](http://coccinelle.lip6.fr/) usage
in systemd.  I also took it a bit further and added infrastructure
to have spatches which should never apply.  This acts as a blacklist.

The reason to do the latter is that coccinelle is *way* more powerful than the
regular expresssions we have in `make syntax-check`.

I started with blacklisting `g_error_free()` directly. The reason that's bad is
it leaves a dangling pointer.

Closes: #754
Approved by: jlebon
This commit is contained in:
Colin Walters authored and Atomic Bot committed 2017-03-30 19:19:54 +00:00
1 parent ee626c2654
commit 305db981d4
12 files changed
+96 -26

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# Run the .cocci files in the tests directory; these act
# as a blacklist.
set -euo pipefail
. $(dirname $0)/libtest.sh
if ! spatch --version 2>/dev/null; then
skip "no spatch; get it from http://coccinelle.lip6.fr/"
fi
if test -z "${OSTREE_UNINSTALLED_SRCDIR:-}"; then
skip "running installed?"
fi
coccitests=$(ls $(dirname $0)/coccinelle/*.cocci)
echo "1.."$(echo ${coccitests} | wc -l)
for cocci in $(dirname $0)/coccinelle/*.cocci; do
echo "Running: ${cocci}"
spatch --very-quiet --dir ${OSTREE_UNINSTALLED_SRCDIR} ${cocci} > cocci.out
if test -s cocci.out; then
sed -e 's/^/# /' < cocci.out >&2
fatal "Failed semantic patch: ${cocci}"
fi
echo ok ${cocci}
done
+2
View File
@@ -0,0 +1,2 @@
Add patches here which should never match in the code; i.e. the suggested
replacement may be junk.
+5
View File
@@ -0,0 +1,5 @@
@@
expression p;
@@
- g_error_free (p);
+ g_clear_error (&p);
+3 -2
View File
@@ -22,10 +22,12 @@
#include "ostree-rollsum.h"
#include "libglnx.h"
int
main (int argc, char **argv)
{
GError *local_error = NULL;
g_autoptr(GError) local_error = NULL;
GError **error = &local_error;
GBytes *from_bytes = NULL;
GBytes *to_bytes = NULL;
@@ -64,7 +66,6 @@ main (int argc, char **argv)
if (local_error)
{
g_printerr ("%s\n", local_error->message);
g_error_free (local_error);
return 1;
}
return 0;