Compare commits

..

No commits in common. "7c57a030e0d654ce0e4d557da826170fb5ac5bc2" and "8e4a44c5853840167227d232a58b34dd09b02380" have entirely different histories.

17 changed files with 80 additions and 59 deletions

View File

@ -2,28 +2,13 @@
expression e;
statement s;
@@
if (
(
!e
|
- e == NULL
+ !e
)
)
{...}
else s
- if (e == NULL)
+ if (!e)
s
@@
expression e;
statement s;
@@
if (
(
e
|
- e != NULL
+ e
)
)
{...}
else s
- if (e != NULL)
+ if (e)
s

View File

@ -1,13 +1,7 @@
@@
/* Disable this transformation in cases where it doesn't make sense or
* where it makes the resulting expression more confusing
*/
position p : script:python() {
not (p[0].file == "src/shared/securebits-util.h" or
p[0].file == "src/core/manager.h" or
p[0].current_element == "log_set_max_level_realm" or
p[0].current_element == "unichar_is_valid")
};
/* 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;
@@
(

View File

@ -1,13 +1,25 @@
/* Limit the number of expressions to 6 for performance reasons */
@@
expression e;
/* Exclude JsonVariant * from the transformation, as it can't work with the
* current version of the IN_SET macro */
typedef JsonVariant;
type T != JsonVariant*;
constant T n0, n1, n2, n3, n4, n5;
constant T n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
@@
(
- e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6 || e == n7 || e == n8 || e == n9
+ IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9)
|
- e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6 || e == n7 || e == n8
+ IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8)
|
- e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6 || e == n7
+ IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7)
|
- e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6
+ IN_SET(e, n0, n1, n2, n3, n4, n5, n6)
|
- e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5
+ IN_SET(e, n0, n1, n2, n3, n4, n5)
|

View File

@ -1,11 +1,22 @@
/* Limit the number of expressions to 6 for performance reasons */
@@
expression e;
typedef JsonVariant;
type T != JsonVariant*;
constant T n0, n1, n2, n3, n4, n5;
constant T n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
@@
(
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9)
|
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8)
|
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7)
|
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6)
|
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5
+ !IN_SET(e, n0, n1, n2, n3, n4, n5)
|

View File

@ -10,6 +10,7 @@ EXCLUDED_PATHS=(
)
top="$(git rev-parse --show-toplevel)"
iso_defs="$top/coccinelle/systemd-definitions.iso"
args=
# Create an array from files tracked by git...
@ -36,7 +37,7 @@ for SCRIPT in ${@-$top/coccinelle/*.cocci} ; do
TMPFILE=`mktemp`
echo "+ spatch --sp-file $SCRIPT $args ..."
parallel --halt now,fail=1 --keep-order --noswap --max-args=20 \
spatch --sp-file $SCRIPT $args ::: "${files[@]}" \
spatch --iso-file $iso_defs --sp-file $SCRIPT $args ::: "${files[@]}" \
2>"$TMPFILE" || cat "$TMPFILE"
echo -e "--x-- Processed $SCRIPT --x--\n"
done

View File

@ -1,15 +1,16 @@
@@
position p : script:python() { p[0].current_element != "test_strjoin" };
expression list args;
@@
- strjoin(args, NULL);
+ strjoin(args);
@@
expression t;
expression list args;
@@
(
- strjoin@p(args, NULL);
+ strjoin(args);
|
- t = strjoin@p(args, NULL);
- t = strjoin(args, NULL);
+ t = strjoin(args);
|
- return strjoin@p(args, NULL);
@@
expression list args;
@@
- return strjoin(args, NULL);
+ return strjoin(args);
)

View File

@ -0,0 +1,20 @@
/* Statement isomorphisms - replace explicit checks against NULL with a
* shorter variant, which relies on C's downgrade-to-bool feature.
* The expression metavariables should be declared as pointers, however,
* that doesn't work well with complex expressions like:
* if (UNIT(p)->default_dependencies != NULL)
*/
Statement
@@
expression X;
statement S;
@@
if (X == NULL) S => if (!X) S
Statement
@@
expression X;
statement S;
@@
if (X != NULL) S => if (X) S

View File

@ -1,7 +1,6 @@
@@
position p : script:python() { not p[0].file.startswith("man/") };
expression e, fmt;
expression list vaargs;
@@
- snprintf@p(e, sizeof(e), fmt, vaargs);
- snprintf(e, sizeof(e), fmt, vaargs);
+ xsprintf(e, fmt, vaargs);

View File

@ -24,7 +24,6 @@ if bashcompletiondir != 'no'
['systemd-cgtop', ''],
['systemd-delta', ''],
['systemd-detect-virt', ''],
['systemd-id128', ''],
['systemd-nspawn', ''],
['systemd-path', ''],
['systemd-run', ''],
@ -33,7 +32,6 @@ if bashcompletiondir != 'no'
[bash_systemctl, ''],
['bootctl', 'ENABLE_EFI'],
['coredumpctl', 'ENABLE_COREDUMP'],
['homectl', 'ENABLE_HOMED'],
['hostnamectl', 'ENABLE_HOSTNAMED'],
['localectl', 'ENABLE_LOCALED'],
['loginctl', 'ENABLE_LOGIND'],

View File

@ -45,7 +45,7 @@ static int unlinkat_harder(
return -errno;
if (!S_ISDIR(st.st_mode))
return -ENOTDIR;
if (FLAGS_SET(st.st_mode, 0700)) /* Already set? */
if ((st.st_mode & 0700) == 0700) /* Already set? */
return -EACCES; /* original error */
if (st.st_uid != geteuid()) /* this only works if the UID matches ours */
return -EACCES;

View File

@ -5502,7 +5502,7 @@ void unit_remove_dependencies(Unit *u, UnitDependencyMask mask) {
done = true;
HASHMAP_FOREACH_KEY(di.data, other, u->dependencies[d]) {
if (FLAGS_SET(~mask, di.origin_mask))
if ((di.origin_mask & ~mask) == di.origin_mask)
continue;
di.origin_mask &= ~mask;
unit_update_dependency_mask(u, d, other, di);
@ -5516,7 +5516,7 @@ void unit_remove_dependencies(Unit *u, UnitDependencyMask mask) {
UnitDependencyInfo dj;
dj.data = hashmap_get(other->dependencies[q], u);
if (FLAGS_SET(~mask, dj.destination_mask))
if ((dj.destination_mask & ~mask) == dj.destination_mask)
continue;
dj.destination_mask &= ~mask;

View File

@ -779,7 +779,7 @@ int dhcp_lease_parse_search_domains(const uint8_t *option, size_t len, char ***d
return r;
n += r;
} else if (FLAGS_SET(c, 0xc0)) {
} else if ((c & 0xc0) == 0xc0) {
/* Pointer */
uint8_t d;

View File

@ -270,7 +270,7 @@ static int dhcp6_client_set_duid_internal(
assert_return(duid_len == 0 || duid != NULL, -EINVAL);
assert_return(IN_SET(client->state, DHCP6_STATE_STOPPED), -EBUSY);
if (duid) {
if (duid != NULL) {
r = dhcp_validate_duid_len(duid_type, duid_len, true);
if (r < 0) {
r = dhcp_validate_duid_len(duid_type, duid_len, false);

View File

@ -363,7 +363,7 @@ int calendar_spec_to_string(const CalendarSpec *c, char **p) {
if (c->utc)
fputs(" UTC", f);
else if (c->timezone) {
else if (c->timezone != NULL) {
fputc(' ', f);
fputs(c->timezone, f);
} else if (IN_SET(c->dst, 0, 1)) {

View File

@ -124,7 +124,7 @@ int path_chown_recursive(
if (fd < 0)
return -errno;
if (!uid_is_valid(uid) && !gid_is_valid(gid) && FLAGS_SET(mask, 07777))
if (!uid_is_valid(uid) && !gid_is_valid(gid) && (mask & 07777) == 07777)
return 0; /* nothing to do */
if (fstat(fd, &st) < 0)
@ -160,7 +160,7 @@ int fd_chown_recursive(
if (!S_ISDIR(st.st_mode))
return -ENOTDIR;
if (!uid_is_valid(uid) && !gid_is_valid(gid) && FLAGS_SET(mask, 07777))
if (!uid_is_valid(uid) && !gid_is_valid(gid) && (mask & 07777) == 07777)
return 0; /* nothing to do */
/* Shortcut, as above */

View File

@ -46,7 +46,7 @@ static void test_tmpdir(const char *id, const char *A, const char *B) {
c = strjoina(a, "/tmp");
assert_se(stat(c, &x) >= 0);
assert_se(S_ISDIR(x.st_mode));
assert_se(FLAGS_SET(x.st_mode, 01777));
assert_se((x.st_mode & 01777) == 01777);
assert_se(rmdir(c) >= 0);
assert_se(rmdir(a) >= 0);
}
@ -57,7 +57,7 @@ static void test_tmpdir(const char *id, const char *A, const char *B) {
d = strjoina(b, "/tmp");
assert_se(stat(d, &y) >= 0);
assert_se(S_ISDIR(y.st_mode));
assert_se(FLAGS_SET(y.st_mode, 01777));
assert_se((y.st_mode & 01777) == 01777);
assert_se(rmdir(d) >= 0);
assert_se(rmdir(b) >= 0);
}

View File

@ -236,7 +236,7 @@ static int get_file_options(const char *vendor, const char *model,
retval = -1;
break;
}
if (!vendor) {
if (vendor == NULL) {
if (!vendor_in)
break;
} else if (vendor_in &&