strv: declare iterator of FOREACH_STRING() in the loop
Same idea as 03677889f0.
No functional change intended. The type of the iterator is generally changed to
be 'const char*' instead of 'char*'. Despite the type commonly used, modifying
the string was not allowed.
I adjusted the naming of some short variables for clarity and reduced the scope
of some variable declarations in code that was being touched anyway.
This commit is contained in:
@@ -30,7 +30,6 @@ static void test_policy_closed(const char *cgroup_path, BPFProgram **installed_p
|
||||
r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_CLOSED, true, cgroup_path, installed_prog);
|
||||
assert_se(r >= 0);
|
||||
|
||||
const char *s;
|
||||
FOREACH_STRING(s, "/dev/null",
|
||||
"/dev/zero",
|
||||
"/dev/full",
|
||||
|
||||
@@ -64,18 +64,14 @@ static void test_ellipsize_mem_one(const char *s, size_t old_length, size_t new_
|
||||
}
|
||||
|
||||
TEST(ellipsize_mem) {
|
||||
const char *s;
|
||||
ssize_t l, k;
|
||||
|
||||
FOREACH_STRING(s,
|
||||
"_XXXXXXXXXXX_", /* ASCII */
|
||||
"_aąęółśćńżźć_", /* two-byte utf-8 */
|
||||
"გამარჯობა", /* multi-byte utf-8 */
|
||||
"你好世界", /* wide characters */
|
||||
"你გą世óoó界") /* a mix */
|
||||
|
||||
for (l = strlen(s); l >= 0; l--)
|
||||
for (k = strlen(s) + 1; k >= 0; k--)
|
||||
for (ssize_t l = strlen(s); l >= 0; l--)
|
||||
for (ssize_t k = strlen(s) + 1; k >= 0; k--)
|
||||
test_ellipsize_mem_one(s, l, k);
|
||||
}
|
||||
|
||||
|
||||
@@ -166,8 +166,6 @@ TEST(load_env_file_6) {
|
||||
}
|
||||
|
||||
TEST(write_and_load_env_file) {
|
||||
const char *v;
|
||||
|
||||
/* Make sure that our writer, parser and the shell agree on what our env var files mean */
|
||||
|
||||
FOREACH_STRING(v,
|
||||
|
||||
+6
-10
@@ -190,19 +190,15 @@ static bool check_user_has_group_with_same_name(const char *name) {
|
||||
}
|
||||
|
||||
static bool is_inaccessible_available(void) {
|
||||
const char *p;
|
||||
|
||||
FOREACH_STRING(p,
|
||||
"/run/systemd/inaccessible/reg",
|
||||
"/run/systemd/inaccessible/dir",
|
||||
"/run/systemd/inaccessible/chr",
|
||||
"/run/systemd/inaccessible/blk",
|
||||
"/run/systemd/inaccessible/fifo",
|
||||
"/run/systemd/inaccessible/sock"
|
||||
) {
|
||||
"/run/systemd/inaccessible/reg",
|
||||
"/run/systemd/inaccessible/dir",
|
||||
"/run/systemd/inaccessible/chr",
|
||||
"/run/systemd/inaccessible/blk",
|
||||
"/run/systemd/inaccessible/fifo",
|
||||
"/run/systemd/inaccessible/sock")
|
||||
if (access(p, F_OK) < 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -998,7 +998,6 @@ TEST(read_full_file_offset_size) {
|
||||
}
|
||||
|
||||
static void test_read_virtual_file_one(size_t max_size) {
|
||||
const char *filename;
|
||||
int r;
|
||||
|
||||
log_info("/* %s (max_size=%zu) */", __func__, max_size);
|
||||
|
||||
+1
-5
@@ -11,16 +11,13 @@
|
||||
#include "util.h"
|
||||
|
||||
TEST(gpt_types_against_architectures) {
|
||||
const char *prefix;
|
||||
int r;
|
||||
|
||||
/* Dumps a table indicating for which architectures we know we have matching GPT partition
|
||||
* types. Also validates whether we can properly categorize the entries. */
|
||||
|
||||
FOREACH_STRING(prefix, "root-", "usr-")
|
||||
for (int a = 0; a < _ARCHITECTURE_MAX; a++) {
|
||||
const char *suffix;
|
||||
|
||||
for (int a = 0; a < _ARCHITECTURE_MAX; a++)
|
||||
FOREACH_STRING(suffix, "", "-verity", "-verity-sig") {
|
||||
_cleanup_free_ char *joined = NULL;
|
||||
sd_id128_t id;
|
||||
@@ -48,7 +45,6 @@ TEST(gpt_types_against_architectures) {
|
||||
|
||||
assert_se(gpt_partition_type_uuid_to_arch(id) == a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
||||
@@ -39,7 +39,6 @@ static int test_hash_password(void) {
|
||||
/* As a warm-up exercise, check if we can hash passwords. */
|
||||
|
||||
bool have_sane_hash = false;
|
||||
const char *hash;
|
||||
|
||||
FOREACH_STRING(hash,
|
||||
"ew3bU1.hoKk4o",
|
||||
@@ -68,7 +67,6 @@ static void test_hash_password_full(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
_cleanup_free_ void *cd_data = NULL;
|
||||
const char *i;
|
||||
int cd_size = 0;
|
||||
|
||||
log_info("sizeof(struct crypt_data): %zu bytes", sizeof(struct crypt_data));
|
||||
|
||||
@@ -114,7 +114,6 @@ int main(int argc, char *argv[]) {
|
||||
_cleanup_(dissected_image_unrefp) DissectedImage *dissected = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *mounted = NULL;
|
||||
pthread_t threads[N_THREADS];
|
||||
const char *fs;
|
||||
sd_id128_t id;
|
||||
int r;
|
||||
|
||||
|
||||
@@ -128,7 +128,6 @@ TEST(mount_flags_to_string) {
|
||||
TEST(bind_remount_recursive) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *tmp = NULL;
|
||||
_cleanup_free_ char *subdir = NULL;
|
||||
const char *p;
|
||||
|
||||
if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) {
|
||||
(void) log_tests_skipped("not running privileged");
|
||||
|
||||
@@ -67,7 +67,6 @@ TEST(path_is_fs_type) {
|
||||
}
|
||||
|
||||
TEST(path_is_temporary_fs) {
|
||||
const char *s;
|
||||
int r;
|
||||
|
||||
FOREACH_STRING(s, "/", "/run", "/sys", "/sys/", "/proc", "/i-dont-exist", "/var", "/var/lib") {
|
||||
@@ -85,7 +84,6 @@ TEST(path_is_temporary_fs) {
|
||||
}
|
||||
|
||||
TEST(path_is_read_only_fs) {
|
||||
const char *s;
|
||||
int r;
|
||||
|
||||
FOREACH_STRING(s, "/", "/run", "/sys", "/sys/", "/proc", "/i-dont-exist", "/var", "/var/lib") {
|
||||
|
||||
@@ -924,12 +924,10 @@ TEST(foreach_string) {
|
||||
"waldo",
|
||||
NULL
|
||||
};
|
||||
const char *x;
|
||||
unsigned i = 0;
|
||||
|
||||
unsigned i = 0;
|
||||
FOREACH_STRING(x, "foo", "bar", "waldo")
|
||||
assert_se(streq_ptr(t[i++], x));
|
||||
|
||||
assert_se(i == 3);
|
||||
|
||||
FOREACH_STRING(x, "zzz")
|
||||
|
||||
@@ -144,7 +144,6 @@ TEST(utf8_escape_non_printable) {
|
||||
}
|
||||
|
||||
TEST(utf8_escape_non_printable_full) {
|
||||
const char *s;
|
||||
FOREACH_STRING(s,
|
||||
"goo goo goo", /* ASCII */
|
||||
"\001 \019\20\a", /* control characters */
|
||||
@@ -210,8 +209,6 @@ TEST(utf8_console_width) {
|
||||
}
|
||||
|
||||
TEST(utf8_to_utf16) {
|
||||
const char *p;
|
||||
|
||||
FOREACH_STRING(p,
|
||||
"abc",
|
||||
"zażółcić gęślą jaźń",
|
||||
|
||||
Reference in New Issue
Block a user