Skip to content

Commit 318a817

Browse files
committed
Refactor: various: Use const char *const * where possible
In the remaining places I could find where it hasn't already been done. This is annoying to look at, but it's correct. char ** and gchar ** are obviously not const, and we should use const where we can. The frustrating thing is that this pointer type is not compatible with char **, so it requires explicit casts. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent db3e966 commit 318a817

11 files changed

Lines changed: 50 additions & 21 deletions

File tree

daemons/execd/pacemaker-execd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ main(int argc, char **argv)
372372

373373
// Open additional log files
374374
if (options.log_files != NULL) {
375-
for (gchar **fname = options.log_files; *fname != NULL; fname++) {
375+
for (const char *const *fname = (const char *const *) options.log_files;
376+
*fname != NULL; fname++) {
377+
376378
rc = pcmk__add_logfile(*fname);
377379

378380
if (rc != pcmk_rc_ok) {

daemons/fenced/fenced_commands.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ get_value_for_target(const char *target, const char *values)
277277

278278
mappings = g_strsplit_set(values, "; \t", 0);
279279

280-
for (gchar **mapping = mappings; (*mapping != NULL) && (value == NULL);
281-
mapping++) {
280+
for (const char *const *mapping = (const char *const *) mappings;
281+
(*mapping != NULL) && (value == NULL); mapping++) {
282282

283283
value = get_value_if_matching(target, *mapping);
284284
}
@@ -961,7 +961,9 @@ build_port_aliases(const char *hostmap, GList **targets)
961961
stripped = g_strstrip(g_strdup(hostmap));
962962
mappings = g_strsplit_set(stripped, "; \t", 0);
963963

964-
for (gchar **mapping = mappings; *mapping != NULL; mapping++) {
964+
for (const char *const *mapping = (const char *const *) mappings;
965+
*mapping != NULL; mapping++) {
966+
965967
gchar **nvpair = NULL;
966968

967969
if (pcmk__str_empty(*mapping)) {
@@ -1881,7 +1883,9 @@ fenced_register_level(xmlNode *msg, pcmk__action_result_t *result)
18811883
*/
18821884
gchar **devices = g_strsplit(value, ",", 0);
18831885

1884-
for (char **dev = devices; (dev != NULL) && (*dev != NULL); dev++) {
1886+
for (const char *const *dev = (const char *const *) devices;
1887+
(dev != NULL) && (*dev != NULL); dev++) {
1888+
18851889
pcmk__trace("Adding device '%s' for %s[%d]", *dev, tp->target, id);
18861890
tp->levels[id] = g_list_append(tp->levels[id],
18871891
pcmk__str_copy(*dev));

daemons/pacemakerd/pacemakerd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ pacemakerd_features_xml(pcmk__output_t *out, va_list args) {
7575
NULL);
7676
out->begin_list(out, NULL, NULL, PCMK_XE_FEATURES);
7777

78-
for (char **s = feature_list; *s != NULL; s++) {
78+
for (const char *const *s = (const char *const *) feature_list; *s != NULL;
79+
s++) {
80+
7981
pcmk__output_create_xml_text_node(out, PCMK_XE_FEATURE, *s);
8082
}
8183

lib/common/logging.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,9 @@ init_tracing(void)
720720
if (tags != NULL) {
721721
gchar **trace_tags = g_strsplit(tags, ",", 0);
722722

723-
for (gchar **tag = trace_tags; *tag != NULL; tag++) {
723+
for (const char *const *tag = (const char *const *) trace_tags;
724+
*tag != NULL; tag++) {
725+
724726
if (pcmk__str_empty(*tag)) {
725727
continue;
726728
}
@@ -1220,7 +1222,9 @@ crm_log_output_fn(const char *file, const char *function, int line, int level, c
12201222

12211223
out_lines = g_strsplit(output, "\n", 0);
12221224

1223-
for (gchar **out_line = out_lines; *out_line != NULL; out_line++) {
1225+
for (const char *const *out_line = (const char *const*) out_lines;
1226+
*out_line != NULL; out_line++) {
1227+
12241228
do_crm_log_alias(level, file, function, line, "%s [ %s ]",
12251229
prefix, *out_line);
12261230
}

lib/common/options_display.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ add_possible_values_default(pcmk__output_t *out,
4141

4242
gchar **values = g_strsplit(option->values, ", ", 0);
4343

44-
for (gchar **value = values; *value != NULL; value++) {
44+
for (const char *const *value = (const char *const *) values;
45+
*value != NULL; value++) {
46+
4547
if (buf->len > 0) {
4648
g_string_append(buf, ", ");
4749
}
@@ -297,7 +299,9 @@ add_possible_values_xml(pcmk__output_t *out,
297299

298300
values = g_strsplit(option->values, ", ", 0);
299301

300-
for (gchar **value = values; *value != NULL; value++) {
302+
for (const char *const *value = (const char *const *) values;
303+
*value != NULL; value++) {
304+
301305
pcmk__output_create_xml_node(out, PCMK_XE_OPTION,
302306
PCMK_XA_VALUE, *value,
303307
NULL);

lib/common/utils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ pcmk__compare_versions(const char *version1, const char *version2)
242242
segments1 = g_strsplit(pcmk__s(match1, ""), ".", 0);
243243
segments2 = g_strsplit(pcmk__s(match2, ""), ".", 0);
244244

245-
for (gchar **segment1 = segments1, **segment2 = segments2;
245+
for (const char *const *segment1 = (const char *const *) segments1,
246+
*const *segment2 = (const char *const *) segments2;
246247
(*segment1 != NULL) || (*segment2 != NULL); ) {
247248

248249
long long value1 = 0;

lib/services/services.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,9 @@ get_directory_list(const char *root, gboolean files, gboolean executable)
14541454

14551455
dir_paths = g_strsplit(root, ":", 0);
14561456

1457-
for (gchar **dir = dir_paths; *dir != NULL; dir++) {
1457+
for (const char *const *dir = (const char *const *) dir_paths;
1458+
*dir != NULL; dir++) {
1459+
14581460
list = g_list_concat(list, gdl_helper(*dir, files, executable));
14591461
}
14601462

lib/services/services_ocf.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ services__list_ocf_providers(void)
4343
// NULL dirs should be impossible if PCMK__OCF_RA_PATH is defined correctly
4444
CRM_CHECK(dirs != NULL, return NULL);
4545

46-
for (gchar **dir = dirs; *dir != NULL; dir++) {
46+
for (const char *const *dir = (const char *const *) dirs; *dir != NULL;
47+
dir++) {
48+
4749
list = g_list_concat(list, services__list_dir(*dir, false));
4850
}
4951

@@ -94,7 +96,9 @@ services__list_ocf_agents(const char *provider)
9496
// NULL dirs should be impossible if PCMK__OCF_RA_PATH is defined correctly
9597
CRM_CHECK(dirs != NULL, return NULL);
9698

97-
for (gchar **dir = dirs; *dir != NULL; dir++) {
99+
for (const char *const *dir = (const char *const *) dirs; *dir != NULL;
100+
dir++) {
101+
98102
char *buf = pcmk__assert_asprintf("%s/%s", *dir, provider);
99103

100104
list = g_list_concat(list, services__list_dir(buf, true));
@@ -140,7 +144,9 @@ services__ocf_agent_exists(const char *provider, const char *agent, char **path)
140144
// NULL dirs should be impossible if PCMK__OCF_RA_PATH is defined correctly
141145
CRM_CHECK(dirs != NULL, return NULL);
142146

143-
for (gchar **dir = dirs; !found && (*dir != NULL); dir++) {
147+
for (const char *const *dir = (const char *const *) dirs;
148+
!found && (*dir != NULL); dir++) {
149+
144150
char *buf = pcmk__assert_asprintf("%s/%s/%s", *dir, provider, agent);
145151
struct stat sb;
146152

tools/cibsecret.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ reachable_hosts(pcmk__output_t *out, GList *all)
321321

322322
g_free(path);
323323
g_ptr_array_add(reachable, NULL);
324-
return (char **) g_ptr_array_free(reachable, FALSE);
324+
return (gchar **) g_ptr_array_free(reachable, FALSE);
325325
}
326326

327327
struct node_data {

tools/crm_mon.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,12 @@ find_section_bit(const char *name) {
302302

303303
static gboolean
304304
apply_exclude(const gchar *excludes, GError **error) {
305-
char **parts = NULL;
305+
gchar **parts = NULL;
306306
gboolean result = TRUE;
307307

308308
parts = g_strsplit(excludes, ",", 0);
309-
for (char **s = parts; *s != NULL; s++) {
309+
310+
for (const char *const *s = (const char *const *) parts; *s != NULL; s++) {
310311
uint32_t bit = find_section_bit(*s);
311312

312313
if (pcmk__str_eq(*s, "all", pcmk__str_none)) {
@@ -332,11 +333,12 @@ apply_exclude(const gchar *excludes, GError **error) {
332333

333334
static gboolean
334335
apply_include(const gchar *includes, GError **error) {
335-
char **parts = NULL;
336+
gchar **parts = NULL;
336337
gboolean result = TRUE;
337338

338339
parts = g_strsplit(includes, ",", 0);
339-
for (char **s = parts; *s != NULL; s++) {
340+
341+
for (const char *const *s = (const char *const *) parts; *s != NULL; s++) {
340342
uint32_t bit = find_section_bit(*s);
341343

342344
if (pcmk__str_eq(*s, "all", pcmk__str_none)) {

0 commit comments

Comments
 (0)