diff options
Diffstat (limited to '')
-rw-r--r-- | dev/coccinelle/bug_on.cocci | 7 | ||||
-rw-r--r-- | dev/coccinelle/cs_endp_flags.cocci | 76 | ||||
-rw-r--r-- | dev/coccinelle/endp_flags.cocci | 76 | ||||
-rw-r--r-- | dev/coccinelle/ha_free.cocci | 6 | ||||
-rw-r--r-- | dev/coccinelle/ist.cocci | 86 | ||||
-rw-r--r-- | dev/coccinelle/realloc_leak.cocci | 6 | ||||
-rw-r--r-- | dev/coccinelle/strcmp.cocci | 309 | ||||
-rw-r--r-- | dev/coccinelle/xalloc_cast.cocci | 11 | ||||
-rw-r--r-- | dev/coccinelle/xalloc_size.cocci | 41 |
9 files changed, 618 insertions, 0 deletions
diff --git a/dev/coccinelle/bug_on.cocci b/dev/coccinelle/bug_on.cocci new file mode 100644 index 0000000..3837879 --- /dev/null +++ b/dev/coccinelle/bug_on.cocci @@ -0,0 +1,7 @@ +@@ +expression E; +@@ + +- if (E) +- ABORT_NOW(); ++ BUG_ON(E); diff --git a/dev/coccinelle/cs_endp_flags.cocci b/dev/coccinelle/cs_endp_flags.cocci new file mode 100644 index 0000000..639d321 --- /dev/null +++ b/dev/coccinelle/cs_endp_flags.cocci @@ -0,0 +1,76 @@ +@@ +struct conn_stream *cs; +expression e; +@@ +( +- (cs->endp->flags & (e)) ++ sc_ep_test(cs, e) +| +- (cs->endp->flags & e) ++ sc_ep_test(cs, e) +| +- cs->endp->flags & (e) ++ sc_ep_test(cs, e) +| +- cs->endp->flags & e ++ sc_ep_test(cs, e) +) + +@@ +struct conn_stream *cs; +expression e; +@@ +( +- cs->endp->flags |= (e) ++ sc_ep_set(cs, e) +| +- cs->endp->flags |= e ++ sc_ep_set(cs, e) +) + +@@ +struct conn_stream *cs; +expression e; +@@ +( +- cs->endp->flags &= ~(e) ++ sc_ep_clr(cs, e) +| +- cs->endp->flags &= (e) ++ sc_ep_clr(cs, ~e) +| +- cs->endp->flags &= ~e ++ sc_ep_clr(cs, e) +| +- cs->endp->flags &= e ++ sc_ep_clr(cs, ~e) +) + +@@ +struct conn_stream *cs; +@@ +- cs->endp->flags = 0 ++ sc_ep_zero(cs) + +@@ +struct conn_stream *cs; +expression e; +@@ +( +- cs->endp->flags = (e) ++ sc_ep_setall(cs, e) +| +- cs->endp->flags = e ++ sc_ep_setall(cs, e) +) + +@@ +struct conn_stream *cs; +@@ +( +- (cs->endp->flags) ++ sc_ep_get(cs) +| +- cs->endp->flags ++ sc_ep_get(cs) +) diff --git a/dev/coccinelle/endp_flags.cocci b/dev/coccinelle/endp_flags.cocci new file mode 100644 index 0000000..fceda27 --- /dev/null +++ b/dev/coccinelle/endp_flags.cocci @@ -0,0 +1,76 @@ +@@ +struct cs_endpoint *endp; +expression e; +@@ +( +- (endp->flags & (e)) ++ se_fl_test(endp, e) +| +- (endp->flags & e) ++ se_fl_test(endp, e) +| +- endp->flags & (e) ++ se_fl_test(endp, e) +| +- endp->flags & e ++ se_fl_test(endp, e) +) + +@@ +struct cs_endpoint *endp; +expression e; +@@ +( +- endp->flags |= (e) ++ se_fl_set(endp, e) +| +- endp->flags |= e ++ se_fl_set(endp, e) +) + +@@ +struct cs_endpoint *endp; +expression e; +@@ +( +- endp->flags &= ~(e) ++ se_fl_clr(endp, e) +| +- endp->flags &= (e) ++ se_fl_clr(endp, ~e) +| +- endp->flags &= ~e ++ se_fl_clr(endp, e) +| +- endp->flags &= e ++ se_fl_clr(endp, ~e) +) + +@@ +struct cs_endpoint *endp; +@@ +- endp->flags = 0 ++ se_fl_zero(endp) + +@@ +struct cs_endpoint *endp; +expression e; +@@ +( +- endp->flags = (e) ++ se_fl_setall(endp, e) +| +- endp->flags = e ++ se_fl_setall(endp, e) +) + +@@ +struct cs_endpoint *endp; +@@ +( +- (endp->flags) ++ se_fl_get(endp) +| +- endp->flags ++ se_fl_get(endp) +) diff --git a/dev/coccinelle/ha_free.cocci b/dev/coccinelle/ha_free.cocci new file mode 100644 index 0000000..0019039 --- /dev/null +++ b/dev/coccinelle/ha_free.cocci @@ -0,0 +1,6 @@ +@ rule @ +expression E; +@@ +- free(E); +- E = NULL; ++ ha_free(&E); diff --git a/dev/coccinelle/ist.cocci b/dev/coccinelle/ist.cocci new file mode 100644 index 0000000..acde626 --- /dev/null +++ b/dev/coccinelle/ist.cocci @@ -0,0 +1,86 @@ +@@ +struct ist i; +expression p, l; +@@ + +( +- i.ptr = p; +- i.len = strlen(i.ptr); ++ i = ist(p); +| +- i.ptr = p; +- i.len = l; ++ i = ist2(p, l); +) + +@@ +@@ + +- ist2(NULL, 0) ++ IST_NULL + +@@ +struct ist i; +expression e; +@@ + +- i.ptr += e; +- i.len -= e; ++ i = istadv(i, e); + +@@ +struct ist i; +@@ + +- i = istadv(i, 1); ++ i = istnext(i); + +@@ +struct ist i; +@@ + +- i.ptr++; +- i.len--; ++ i = istnext(i); + +@@ +struct ist i; +@@ + +- (\(i.ptr\|istptr(i)\) + \(i.len\|istlen(i)\)) ++ istend(i) + +@@ +struct ist i; +expression e; +@@ + +- if (\(i.len\|istlen(i)\) > e) { i.len = e; } ++ i = isttrim(i, e); + +@@ +struct ist i; +struct buffer *b; +@@ + +- chunk_memcat(b, \(i.ptr\|istptr(i)\) , \(i.len\|istlen(i)\)); ++ chunk_istcat(b, i); + +@@ +struct ist i; +@@ + +- i.ptr != NULL ++ isttest(i) + +@@ +char *s; +@@ + +( +- ist2(s, strlen(s)) ++ ist(s) +| +- ist2(strdup(s), strlen(s)) ++ ist(strdup(s)) +) diff --git a/dev/coccinelle/realloc_leak.cocci b/dev/coccinelle/realloc_leak.cocci new file mode 100644 index 0000000..c201b80 --- /dev/null +++ b/dev/coccinelle/realloc_leak.cocci @@ -0,0 +1,6 @@ +@@ +expression E; +expression F; +@@ + +* E = realloc(E, F); diff --git a/dev/coccinelle/strcmp.cocci b/dev/coccinelle/strcmp.cocci new file mode 100644 index 0000000..f6064bf --- /dev/null +++ b/dev/coccinelle/strcmp.cocci @@ -0,0 +1,309 @@ +@@ +statement S; +expression E; +expression F; +@@ + + if ( +( +dns_hostname_cmp +| +eb_memcmp +| +memcmp +| +strcasecmp +| +strcmp +| +strncasecmp +| +strncmp +) +- (E, F) ++ (E, F) != 0 + ) +( + S +| + { ... } +) + +@@ +statement S; +expression E; +expression F; +@@ + + if ( +- ! +( +dns_hostname_cmp +| +eb_memcmp +| +memcmp +| +strcasecmp +| +strcmp +| +strncasecmp +| +strncmp +) +- (E, F) ++ (E, F) == 0 + ) +( + S +| + { ... } +) + +@@ +expression E; +expression F; +expression G; +@@ + +( +G && +( +dns_hostname_cmp +| +eb_memcmp +| +memcmp +| +strcasecmp +| +strcmp +| +strncasecmp +| +strncmp +) +- (E, F) ++ (E, F) != 0 +) + +@@ +expression E; +expression F; +expression G; +@@ + +( +G || +( +dns_hostname_cmp +| +eb_memcmp +| +memcmp +| +strcasecmp +| +strcmp +| +strncasecmp +| +strncmp +) +- (E, F) ++ (E, F) != 0 +) + +@@ +expression E; +expression F; +expression G; +@@ + +( +( +dns_hostname_cmp +| +eb_memcmp +| +memcmp +| +strcasecmp +| +strcmp +| +strncasecmp +| +strncmp +) +- (E, F) ++ (E, F) != 0 +&& G +) + +@@ +expression E; +expression F; +expression G; +@@ + +( +( +dns_hostname_cmp +| +eb_memcmp +| +memcmp +| +strcasecmp +| +strcmp +| +strncasecmp +| +strncmp +) +- (E, F) ++ (E, F) != 0 +|| G +) + +@@ +expression E; +expression F; +expression G; +@@ + +( +G && +- ! +( +dns_hostname_cmp +| +eb_memcmp +| +memcmp +| +strcasecmp +| +strcmp +| +strncasecmp +| +strncmp +) +- (E, F) ++ (E, F) == 0 +) + +@@ +expression E; +expression F; +expression G; +@@ + +( +G || +- ! +( +dns_hostname_cmp +| +eb_memcmp +| +memcmp +| +strcasecmp +| +strcmp +| +strncasecmp +| +strncmp +) +- (E, F) ++ (E, F) == 0 +) + +@@ +expression E; +expression F; +expression G; +@@ + +( +- ! +( +dns_hostname_cmp +| +eb_memcmp +| +memcmp +| +strcasecmp +| +strcmp +| +strncasecmp +| +strncmp +) +- (E, F) ++ (E, F) == 0 +&& G +) + +@@ +expression E; +expression F; +expression G; +@@ + +( +- ! +( +dns_hostname_cmp +| +eb_memcmp +| +memcmp +| +strcasecmp +| +strcmp +| +strncasecmp +| +strncmp +) +- (E, F) ++ (E, F) == 0 +|| G +) + +@@ +expression E; +expression F; +expression G; +@@ + +( +- ! +( +dns_hostname_cmp +| +eb_memcmp +| +memcmp +| +strcasecmp +| +strcmp +| +strncasecmp +| +strncmp +) +- (E, F) ++ (E, F) == 0 +) diff --git a/dev/coccinelle/xalloc_cast.cocci b/dev/coccinelle/xalloc_cast.cocci new file mode 100644 index 0000000..75baa00 --- /dev/null +++ b/dev/coccinelle/xalloc_cast.cocci @@ -0,0 +1,11 @@ +@@ +type T; +@@ + +- (T*) +( +malloc +| +calloc +) + (...) diff --git a/dev/coccinelle/xalloc_size.cocci b/dev/coccinelle/xalloc_size.cocci new file mode 100644 index 0000000..80808e3 --- /dev/null +++ b/dev/coccinelle/xalloc_size.cocci @@ -0,0 +1,41 @@ +@@ +type T; +expression E; +expression t; +@@ + +( + t = calloc(E, sizeof(*t)) +| +- t = calloc(E, sizeof(T)) ++ t = calloc(E, sizeof(*t)) +) + +@@ +type T; +T *x; +@@ + + x = malloc( +- sizeof(T) ++ sizeof(*x) + ) + +@@ +type T; +T *x; +@@ + + x = calloc(1, +- sizeof(T) ++ sizeof(*x) + ) + +@@ +@@ + + calloc( ++ 1, + ... +- ,1 + ) |