Skip to content

Commit d6a2ffc

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 eade73c commit d6a2ffc

File tree

11 files changed

+50
-21
lines changed

11 files changed

+50
-21
lines changed

daemons/execd/pacemaker-execd.c

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

376376
// Open additional log files
377377
if (options.log_files != NULL) {
378-
for (gchar **fname = options.log_files; *fname != NULL; fname++) {
378+
for (const char *const *fname = (const char *const *) options.log_files;
379+
*fname != NULL; fname++) {
380+
379381
rc = pcmk__add_logfile(*fname);
380382

381383
if (rc != pcmk_rc_ok) {

daemons/fenced/fenced_commands.c

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

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

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

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

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

968970
if (pcmk__str_empty(*mapping)) {
@@ -1882,7 +1884,9 @@ fenced_register_level(xmlNode *msg, pcmk__action_result_t *result)
18821884
*/
18831885
gchar **devices = g_strsplit(value, ",", 0);
18841886

1885-
for (char **dev = devices; (dev != NULL) && (*dev != NULL); dev++) {
1887+
for (const char *const *dev = (const char *const *) devices;
1888+
(dev != NULL) && (*dev != NULL); dev++) {
1889+
18861890
pcmk__trace("Adding device '%s' for %s[%d]", *dev, tp->target, id);
18871891
tp->levels[id] = g_list_append(tp->levels[id],
18881892
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
@@ -719,7 +719,9 @@ init_tracing(void)
719719
if (tags != NULL) {
720720
gchar **trace_tags = g_strsplit(tags, ",", 0);
721721

722-
for (gchar **tag = trace_tags; *tag != NULL; tag++) {
722+
for (const char *const *tag = (const char *const *) trace_tags;
723+
*tag != NULL; tag++) {
724+
723725
if (pcmk__str_empty(*tag)) {
724726
continue;
725727
}
@@ -1219,7 +1221,9 @@ crm_log_output_fn(const char *file, const char *function, int line, int level, c
12191221

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

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

lib/common/options_display.c

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

4040
gchar **values = g_strsplit(option->values, ", ", 0);
4141

42-
for (gchar **value = values; *value != NULL; value++) {
42+
for (const char *const *value = (const char *const *) values;
43+
*value != NULL; value++) {
44+
4345
if (buf->len > 0) {
4446
g_string_append(buf, ", ");
4547
}
@@ -295,7 +297,9 @@ add_possible_values_xml(pcmk__output_t *out,
295297

296298
values = g_strsplit(option->values, ", ", 0);
297299

298-
for (gchar **value = values; *value != NULL; value++) {
300+
for (const char *const *value = (const char *const *) values;
301+
*value != NULL; value++) {
302+
299303
pcmk__output_create_xml_node(out, PCMK_XE_OPTION,
300304
PCMK_XA_VALUE, *value,
301305
NULL);

lib/common/utils.c

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

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

247248
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
@@ -304,11 +304,12 @@ find_section_bit(const char *name) {
304304

305305
static gboolean
306306
apply_exclude(const gchar *excludes, GError **error) {
307-
char **parts = NULL;
307+
gchar **parts = NULL;
308308
gboolean result = TRUE;
309309

310310
parts = g_strsplit(excludes, ",", 0);
311-
for (char **s = parts; *s != NULL; s++) {
311+
312+
for (const char *const *s = (const char *const *) parts; *s != NULL; s++) {
312313
uint32_t bit = find_section_bit(*s);
313314

314315
if (pcmk__str_eq(*s, "all", pcmk__str_none)) {
@@ -334,11 +335,12 @@ apply_exclude(const gchar *excludes, GError **error) {
334335

335336
static gboolean
336337
apply_include(const gchar *includes, GError **error) {
337-
char **parts = NULL;
338+
gchar **parts = NULL;
338339
gboolean result = TRUE;
339340

340341
parts = g_strsplit(includes, ",", 0);
341-
for (char **s = parts; *s != NULL; s++) {
342+
343+
for (const char *const *s = (const char *const *) parts; *s != NULL; s++) {
342344
uint32_t bit = find_section_bit(*s);
343345

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

0 commit comments

Comments
 (0)