From a30fdf857b7201a206b90f55473af84b67b19b13 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 2 Apr 2024 18:06:24 +0200 Subject: [PATCH 1/4] Use IN_SET() more --- src/cryptsetup/cryptsetup.c | 2 +- src/shared/pkcs11-util.c | 4 ++-- src/shared/ptyfwd.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 7099f68f88..34ad9ebd14 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -530,7 +530,7 @@ static int parse_one_option(const char *option) { * - text descriptions prefixed with "%:" or "%keyring:". * - text description with no prefix. * - numeric keyring id (ignored in current patch set). */ - if (*val == '@' || *val == '%') + if (IN_SET(*val, '@', '%')) keyring = strndup(val, sep - val); else /* add type prefix if missing (crypt_set_keyring_to_link() expects it) */ diff --git a/src/shared/pkcs11-util.c b/src/shared/pkcs11-util.c index e6feba44bd..8727fe2484 100644 --- a/src/shared/pkcs11-util.c +++ b/src/shared/pkcs11-util.c @@ -1711,7 +1711,7 @@ static int pkcs11_acquire_public_key_callback( switch (attributes[i].type) { case CKA_CLASS: { CK_OBJECT_CLASS requested_class = *((CK_OBJECT_CLASS*) attributes[i].pValue); - if (requested_class != CKO_PUBLIC_KEY && requested_class != CKO_CERTIFICATE) + if (!IN_SET(requested_class, CKO_PUBLIC_KEY, CKO_CERTIFICATE)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Selected PKCS#11 object is not a public key or certificate, refusing."); break; @@ -1743,7 +1743,7 @@ static int pkcs11_acquire_public_key_callback( candidate_attributes[0].ulValueLen = sizeof(class); candidate_attributes[1].ulValueLen = sizeof(type); rv = m->C_GetAttributeValue(session, candidate, candidate_attributes, ELEMENTSOF(candidate_attributes)); - if (rv != CKR_OK && rv != CKR_ATTRIBUTE_TYPE_INVALID) + if (!IN_SET(rv, CKR_OK, CKR_ATTRIBUTE_TYPE_INVALID)) return log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to get attributes of a selected candidate: %s", sym_p11_kit_strerror(rv)); diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c index bdbd79087c..7bd8dd6d89 100644 --- a/src/shared/ptyfwd.c +++ b/src/shared/ptyfwd.c @@ -478,7 +478,7 @@ static int pty_forward_ansi_process(PTYForward *f, size_t offset) { * since we cannot lookahead to see if the Esc is followed by a \ * we cut a corner here and assume it will be \. */ - if (c == '\x07' || c == '\x1b') { + if (IN_SET(c, '\x07', '\x1b')) { r = insert_window_title_fix(f, i+1); if (r < 0) return r; From 516bb9c0be58e78fdd277a76ac026d2336189f44 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 2 Apr 2024 18:07:50 +0200 Subject: [PATCH 2/4] Simplify a couple of conditions --- src/ssh-generator/ssh-generator.c | 4 +--- src/test/test-dirent-util.c | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ssh-generator/ssh-generator.c b/src/ssh-generator/ssh-generator.c index 5e03783543..3b9987b581 100644 --- a/src/ssh-generator/ssh-generator.c +++ b/src/ssh-generator/ssh-generator.c @@ -401,10 +401,8 @@ static int parse_credentials(void) { int r; r = read_credential_with_decryption("ssh.listen", (void*) &b, &sz); - if (r < 0) + if (r <= 0) return r; - if (r == 0) - return 0; _cleanup_fclose_ FILE *f = NULL; f = fmemopen_unlocked(b, sz, "r"); diff --git a/src/test/test-dirent-util.c b/src/test/test-dirent-util.c index be0496904f..8192a53e6f 100644 --- a/src/test/test-dirent-util.c +++ b/src/test/test-dirent-util.c @@ -68,7 +68,7 @@ TEST (test_dirent_is_file) { } dir = opendir(t); - if (dir == NULL) { + if (!dir) { log_error_errno(errno, "Failed to open directory '%s': %m", t); exit(EXIT_FAILURE); } @@ -144,7 +144,7 @@ TEST (test_dirent_is_file_with_suffix) { } dir = opendir(t); - if (dir == NULL) { + if (!dir) { log_error_errno(errno, "Failed to open directory '%s': %m", t); exit(EXIT_FAILURE); } From f9ecb076725b80b88604c30b6f262c98558308e0 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 2 Apr 2024 18:08:30 +0200 Subject: [PATCH 3/4] sysext: use mfree() in one more place --- src/sysext/sysext.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c index b984e9b9a0..79b016f9c3 100644 --- a/src/sysext/sysext.c +++ b/src/sysext/sysext.c @@ -748,8 +748,7 @@ static OverlayFSPaths *overlayfs_paths_free(OverlayFSPaths *op) { free(op->work_dir); strv_free(op->lower_dirs); - free(op); - return NULL; + return mfree(op); } DEFINE_TRIVIAL_CLEANUP_FUNC(OverlayFSPaths *, overlayfs_paths_free); From 861316e5ab887d8c035ba8fa451eaab8a33c9bc6 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 2 Apr 2024 18:08:50 +0200 Subject: [PATCH 4/4] test: use free() instead of mfree() Since we don't use the returned value anyway. --- src/test/test-string-util.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index 3b003e885f..67f332db8e 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -375,31 +375,31 @@ TEST(strjoin) { actual = strjoin("", "foo", "bar"); assert_se(streq(actual, "foobar")); - mfree(actual); + free(actual); actual = strjoin("foo", "bar", "baz"); assert_se(streq(actual, "foobarbaz")); - mfree(actual); + free(actual); actual = strjoin("foo", "", "bar", "baz"); assert_se(streq(actual, "foobarbaz")); - mfree(actual); + free(actual); actual = strjoin("foo", NULL); assert_se(streq(actual, "foo")); - mfree(actual); + free(actual); actual = strjoin(NULL, NULL); assert_se(streq(actual, "")); - mfree(actual); + free(actual); actual = strjoin(NULL, "foo"); assert_se(streq(actual, "")); - mfree(actual); + free(actual); actual = strjoin("foo", NULL, "bar"); assert_se(streq(actual, "foo")); - mfree(actual); + free(actual); } TEST(strcmp_ptr) {