tree-wide: Fix constness issues with newer glibc (#39896)

Latest glibc uses _Generic to have strstr() and other functions return
const char* or char* based on whether the input is a const char* or a
char*. This causes build failures as we previously always expected a
char*.

Let's fix the compilation failures and add our own macros similar to
glibc's to have string functions that return a mutable or const pointer
depending on the input.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2025-11-26 00:32:54 +01:00
committed by GitHub
27 changed files with 109 additions and 89 deletions
+2 -2
View File
@@ -1639,7 +1639,6 @@ static int bus_append_root_hash(sd_bus_message *m, const char *field, const char
}
static int bus_append_root_hash_signature(sd_bus_message *m, const char *field, const char *eq) {
char *value;
_cleanup_free_ void *roothash_sig_decoded = NULL;
size_t roothash_sig_decoded_size = 0;
int r;
@@ -1648,7 +1647,8 @@ static int bus_append_root_hash_signature(sd_bus_message *m, const char *field,
if (path_is_absolute(eq))
return bus_append_string(m, "RootHashSignaturePath", eq);
if (!(value = startswith(eq, "base64:")))
const char *value = startswith(eq, "base64:");
if (!value)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to decode %s value '%s': neither a path nor starts with 'base64:'.",
field, eq);
+1 -1
View File
@@ -298,7 +298,7 @@ bool pager_have(void) {
int show_man_page(const char *desc, bool null_stdio) {
const char *args[4] = { "man", NULL, NULL, NULL };
char *e = NULL;
const char *e = NULL;
pid_t pid;
size_t k;
int r;
+1 -1
View File
@@ -2505,7 +2505,7 @@ uint32_t scmp_act_kill_process(void) {
int parse_syscall_and_errno(const char *in, char **name, int *error) {
_cleanup_free_ char *n = NULL;
char *p;
const char *p;
int e = -1;
assert(in);
+1 -1
View File
@@ -343,7 +343,7 @@ static int make_choice(
unsigned found_tries_done = UINT_MAX, found_tries_left = UINT_MAX;
_cleanup_free_ char *dname = NULL;
size_t found_architecture_index = SIZE_MAX;
const char *e;
char *e;
dname = strdup((*entry)->d_name);
if (!dname)