From 2034c8b8838c9f42d1dc16fbda23d9bc3a2c6f02 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 8 May 2022 12:30:51 +0200 Subject: [PATCH] tree-wide: drop de-constifying casts for strv iteration When the the iterator variable is declared automatically, it "inherits" the const/non-const status from the argument. We don't need to cast a const table to non-const. If we had a programming error and tried to modify the string, the compiler could now catch this. --- src/core/manager.c | 2 +- src/shared/bootspec.c | 2 +- src/shared/conf-parser.c | 2 +- src/test/test-fs-util.c | 4 ++-- src/test/test-sysctl-util.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/manager.c b/src/core/manager.c index d09d14911c..98daa764eb 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -3655,7 +3655,7 @@ static bool generator_path_any(const char* const* paths) { /* Optimize by skipping the whole process by not creating output directories * if no generators are found. */ - STRV_FOREACH(path, (char**) paths) + STRV_FOREACH(path, paths) if (access(*path, F_OK) == 0) found = true; else if (errno != ENOENT) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 91cb605fb1..f39d4da6d5 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -960,7 +960,7 @@ int boot_config_augment_from_loader( if (!c) return log_oom(); - STRV_FOREACH_PAIR(a, b, (char**) title_table) + STRV_FOREACH_PAIR(a, b, title_table) if (streq(*a, *i)) { t = strdup(*b); if (!t) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index a84c47cd26..6bd3ab38db 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -497,7 +497,7 @@ static int config_parse_many_files( } /* First read the first found main config file. */ - STRV_FOREACH(fn, (char**) conf_files) { + STRV_FOREACH(fn, conf_files) { r = config_parse(NULL, *fn, NULL, sections, lookup, table, flags, userdata, &st); if (r < 0) return r; diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index f24e97b4cc..5d9d99e272 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -712,7 +712,7 @@ TEST(rename_noreplace) { j = strjoina(z, table[4]); (void) symlink("foobar", j); - STRV_FOREACH(a, (char**) table) { + STRV_FOREACH(a, table) { _cleanup_free_ char *x = NULL, *y = NULL; x = strjoin(z, *a); @@ -723,7 +723,7 @@ TEST(rename_noreplace) { continue; } - STRV_FOREACH(b, (char**) table) { + STRV_FOREACH(b, table) { _cleanup_free_ char *w = NULL; w = strjoin(z, *b); diff --git a/src/test/test-sysctl-util.c b/src/test/test-sysctl-util.c index 02180dc4be..81207f5cfd 100644 --- a/src/test/test-sysctl-util.c +++ b/src/test/test-sysctl-util.c @@ -27,7 +27,7 @@ static const char* const cases[] = { }; TEST(sysctl_normalize) { - STRV_FOREACH_PAIR(s, expected, (const char**) cases) { + STRV_FOREACH_PAIR(s, expected, cases) { _cleanup_free_ char *t; assert_se(t = strdup(*s)); -- 2.25.1