Skip to content

Commit 71c969e

Browse files
committed
Fix: Discarded-qualifiers errors in string searching functions
Currently Naemon uses a mix of (char *) and (const char *) as input for different string functions such as strpbrk() or strchr(). Modern compilers and stricter build flags (-Werror) throw errors when the result of string searching functions like strpbrk() or strchr() is assigned to a non-const pointer, especially when the input was cast to const char*. This commit adds explicit (char *) casts to the return values of strpbrk and strchr to ensure compatibility across different compiler versions and to satisfy -Werror=discarded-qualifiers. Affected functions: - strpbrk - strchr Issues: - #530 - #522 Signed-off-by: nook24 <info@nook24.eu>
1 parent 611a5b6 commit 71c969e

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

lib/nspath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static inline int path_components(const char *path)
2929
int comps = 1;
3030
if (!path)
3131
return 0;
32-
for (slash = strchr(path, '/'); slash; slash = strchr(slash + 1, '/'))
32+
for (slash = (char *)strchr(path, '/'); slash; slash = strchr(slash + 1, '/'))
3333
comps++;
3434
return comps;
3535
}

src/naemon/checks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct check_output *parse_output(const char *buf, struct check_output *check_ou
111111
perf_data_string = g_string_new(NULL);
112112
tmp = strtok_r(tmpbuf, "\n", &saveptr);
113113
if (tmp != NULL) {
114-
p = strpbrk((const char *) tmp, "|");
114+
p = (char *)strpbrk((const char *) tmp, "|");
115115
}
116116
if (p == NULL) {
117117
/* No perfdata in first line of output. */
@@ -138,7 +138,7 @@ struct check_output *parse_output(const char *buf, struct check_output *check_ou
138138
if ((tmp = strtok_r(NULL, "", &saveptr))) {
139139

140140
/* Is there a perf data delimiter somewhere in the long output? */
141-
p = strpbrk((const char *) tmp, "|");
141+
p = (char *)strpbrk((const char *) tmp, "|");
142142
if (p == NULL) {
143143
/* No more perfdata, rest is long output*/
144144
check_output->long_output = nm_strdup(tmp);

src/naemon/objects_command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ command *find_bang_command(const char *name)
9797
if (!name)
9898
return NULL;
9999

100-
bang = strchr(name, '!');
100+
bang = (char *)strchr(name, '!');
101101
if (!bang)
102102
return find_command(name);
103103
*bang = 0;

src/naemon/workers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static struct wproc_list *get_wproc_list(const char *cmd)
110110
return &workers;
111111

112112
/* first, look for a specialized worker for this command */
113-
if ((space = strchr(cmd, ' ')) != NULL) {
113+
if ((space = (char *)strchr(cmd, ' ')) != NULL) {
114114
int namelen = (unsigned long)space - (unsigned long)cmd;
115115
cmd_name = nm_calloc(1, namelen + 1);
116116
memcpy(cmd_name, cmd, namelen);

0 commit comments

Comments
 (0)