From ccd52940d06fc6ba06f44f7ea64f056529c0beb0 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 29 Apr 2019 16:12:41 +0200 Subject: coccinelle: further restrict certain transformations Some transformations generate results we don't want to keep, so let's disable such transformations for specific files. Also, disable const-strlen.cocci everywhere, as the STRLEN macro has a pretty limited scope, so the transformation generates false positives in most cases. --- coccinelle/const-strlen.cocci | 14 -------- coccinelle/const-strlen.disabled | 14 ++++++++ coccinelle/dup-fcntl.cocci | 4 ++- coccinelle/flags-set.cocci | 19 ++++++----- coccinelle/isempty.cocci | 72 +++++++++++++++------------------------- coccinelle/synthetic-errno.cocci | 6 ++++ 6 files changed, 60 insertions(+), 69 deletions(-) delete mode 100644 coccinelle/const-strlen.cocci create mode 100644 coccinelle/const-strlen.disabled diff --git a/coccinelle/const-strlen.cocci b/coccinelle/const-strlen.cocci deleted file mode 100644 index 30a6e5a88e..0000000000 --- a/coccinelle/const-strlen.cocci +++ /dev/null @@ -1,14 +0,0 @@ -@@ -constant s; -@@ -( -#define STRLEN -& -- sizeof(s)-1 -+ STRLEN(s) -) -@@ -constant s; -@@ -- strlen(s) -+ STRLEN(s) diff --git a/coccinelle/const-strlen.disabled b/coccinelle/const-strlen.disabled new file mode 100644 index 0000000000..30a6e5a88e --- /dev/null +++ b/coccinelle/const-strlen.disabled @@ -0,0 +1,14 @@ +@@ +constant s; +@@ +( +#define STRLEN +& +- sizeof(s)-1 ++ STRLEN(s) +) +@@ +constant s; +@@ +- strlen(s) ++ STRLEN(s) diff --git a/coccinelle/dup-fcntl.cocci b/coccinelle/dup-fcntl.cocci index ef13564282..8b133b3a24 100644 --- a/coccinelle/dup-fcntl.cocci +++ b/coccinelle/dup-fcntl.cocci @@ -1,5 +1,7 @@ @@ +/* We want to stick with dup() in test-fd-util.c */ +position p : script:python() { p[0].file != "src/test/test-fd-util.c" }; expression fd; @@ -- dup(fd) +- dup@p(fd) + fcntl(fd, F_DUPFD, 3) diff --git a/coccinelle/flags-set.cocci b/coccinelle/flags-set.cocci index 1a70717e76..73966b02e5 100644 --- a/coccinelle/flags-set.cocci +++ b/coccinelle/flags-set.cocci @@ -1,15 +1,16 @@ @@ +/* Disable this transformation for the securebits-util.h, as it makes + * the expression there confusing. */ +position p : script:python() { p[0].file != "src/shared/securebits-util.h" }; expression x, y; @@ -- ((x) & (y)) == (y) +( +- ((x@p) & (y)) == (y) + FLAGS_SET(x, y) -@@ -expression x, y; -@@ -- (x & (y)) == (y) +| +- (x@p & (y)) == (y) + FLAGS_SET(x, y) -@@ -expression x, y; -@@ -- ((x) & y) == y +| +- ((x@p) & y) == y + FLAGS_SET(x, y) +) diff --git a/coccinelle/isempty.cocci b/coccinelle/isempty.cocci index d8d5275889..e0a9f07ca6 100644 --- a/coccinelle/isempty.cocci +++ b/coccinelle/isempty.cocci @@ -1,60 +1,42 @@ @@ +/* Disable this transformation for the test-string-util.c */ +position p : script:python() { p[0].file != "src/test/test-string-util.c" }; expression s; @@ -- strv_length(s) == 0 +( +- strv_length@p(s) == 0 + strv_isempty(s) -@@ -expression s; -@@ -- strv_length(s) <= 0 +| +- strv_length@p(s) <= 0 + strv_isempty(s) -@@ -expression s; -@@ -- strv_length(s) > 0 +| +- strv_length@p(s) > 0 + !strv_isempty(s) -@@ -expression s; -@@ -- strv_length(s) != 0 +| +- strv_length@p(s) != 0 + !strv_isempty(s) -@@ -expression s; -@@ -- strlen(s) == 0 +| +- strlen@p(s) == 0 + isempty(s) -@@ -expression s; -@@ -- strlen(s) <= 0 +| +- strlen@p(s) <= 0 + isempty(s) -@@ -expression s; -@@ -- strlen(s) > 0 +| +- strlen@p(s) > 0 + !isempty(s) -@@ -expression s; -@@ -- strlen(s) != 0 +| +- strlen@p(s) != 0 + !isempty(s) -@@ -expression s; -@@ -- strlen_ptr(s) == 0 +| +- strlen_ptr@p(s) == 0 + isempty(s) -@@ -expression s; -@@ -- strlen_ptr(s) <= 0 +| +- strlen_ptr@p(s) <= 0 + isempty(s) -@@ -expression s; -@@ -- strlen_ptr(s) > 0 +| +- strlen_ptr@p(s) > 0 + !isempty(s) -@@ -expression s; -@@ -- strlen_ptr(s) != 0 +| +- strlen_ptr@p(s) != 0 + !isempty(s) +) diff --git a/coccinelle/synthetic-errno.cocci b/coccinelle/synthetic-errno.cocci index 645bfc945f..3ddb69cb4c 100644 --- a/coccinelle/synthetic-errno.cocci +++ b/coccinelle/synthetic-errno.cocci @@ -2,9 +2,15 @@ expression e; expression list args; @@ +( +/* Ignore one specific case in src/shared/bootspec.c where we want to stick + * with the log_debug() + return pattern */ +log_debug("Found no default boot entry :("); +| - log_debug(args); - return -e; + return log_debug_errno(SYNTHETIC_ERRNO(e), args); +) @@ expression e; expression list args; -- cgit v1.2.1