]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: Fix constness issues with newer glibc 40868/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 25 Nov 2025 15:46:04 +0000 (16:46 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 27 Feb 2026 21:57:05 +0000 (21:57 +0000)
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.

(cherry picked from commit 0bac1ed2422f15308414dd1e9d09812a966b0348)
(cherry picked from commit 1a2e23b88734ec4be3af2eca651ec75a56161c5f)

24 files changed:
src/basic/proc-cmdline.c
src/basic/socket-util.c
src/basic/sort-util.h
src/basic/string-util.c
src/basic/string-util.h
src/basic/strv.c
src/basic/strv.h
src/basic/time-util.c
src/basic/unit-name.c
src/cryptsetup/cryptsetup-generator.c
src/fundamental/macro-fundamental.h
src/fundamental/string-util-fundamental.c
src/fundamental/string-util-fundamental.h
src/home/homed-manager.c
src/journal/journalctl-filter.c
src/libsystemd/sd-bus/sd-bus.c
src/libsystemd/sd-hwdb/sd-hwdb.c
src/libsystemd/sd-journal/catalog.c
src/network/networkd-dhcp-server.c
src/shared/bus-unit-util.c
src/shared/pager.c
src/shared/seccomp-util.c
src/shared/vpick.c
src/udev/udev-builtin-net_id.c

index 4ffb90b69624e6204cef65a2102178dd4b62e904..de7b8f19ee171e03c8733aa0e3a8ec101ce18551 100644 (file)
@@ -165,9 +165,7 @@ int proc_cmdline_strv(char ***ret) {
 }
 
 static char *mangle_word(const char *word, ProcCmdlineFlags flags) {
-        char *c;
-
-        c = startswith(word, "rd.");
+        char *c = (char*) startswith(word, "rd.");
         if (c) {
                 /* Filter out arguments that are intended only for the initrd */
 
@@ -184,6 +182,8 @@ static char *mangle_word(const char *word, ProcCmdlineFlags flags) {
         return (char*) word;
 }
 
+#define mangle_word(word, flags) const_generic(word, mangle_word(word, flags))
+
 static int proc_cmdline_parse_strv(char **args, proc_cmdline_parse_t parse_item, void *data, ProcCmdlineFlags flags) {
         int r;
 
index 43eb11242ba511eab7addd45c417af3313ce5c62..b8dd24acf55bdb7b1830b210b9a02898ce6dd435 100644 (file)
@@ -1756,7 +1756,7 @@ int vsock_parse_cid(const char *s, unsigned *ret) {
 int socket_address_parse_vsock(SocketAddress *ret_address, const char *s) {
         /* AF_VSOCK socket in vsock:cid:port notation */
         _cleanup_free_ char *n = NULL;
-        char *e, *cid_start;
+        const char *e, *cid_start;
         unsigned port, cid;
         int type, r;
 
index 9c818bd74706dd42652885c4531ace674edcb19a..b0f15f71dabe413318ec03199e7a0a49de40334f 100644 (file)
@@ -25,13 +25,13 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
  * Normal bsearch requires base to be nonnull. Here were require
  * that only if nmemb > 0.
  */
-static inline void* bsearch_safe(const void *key, const void *base,
+static inline const void* bsearch_safe(const void *key, const void *base,
                                  size_t nmemb, size_t size, comparison_fn_t compar) {
         if (nmemb <= 0)
                 return NULL;
 
         assert(base);
-        return bsearch(key, base, nmemb, size, compar);
+        return const_generic((base), bsearch(key, base, nmemb, size, compar));
 }
 
 #define typesafe_bsearch(k, b, n, func)                                 \
index dd35b55d8e54a63a4692b2905eafd7b9a03c8a06..e0aabcbabd14f3c00ecc310cef47001c066d36a6 100644 (file)
@@ -1057,7 +1057,7 @@ int split_pair(const char *s, const char *sep, char **l, char **r) {
         if (isempty(sep))
                 return -EINVAL;
 
-        x = strstr(s, sep);
+        x = (char*) strstr(s, sep);
         if (!x)
                 return -EINVAL;
 
@@ -1395,16 +1395,14 @@ char* strdupcspn(const char *a, const char *reject) {
         return strndup(a, strcspn(a, reject));
 }
 
-char* find_line_startswith(const char *haystack, const char *needle) {
-        char *p;
-
+char* find_line_startswith_internal(const char *haystack, const char *needle) {
         assert(haystack);
         assert(needle);
 
         /* Finds the first line in 'haystack' that starts with the specified string. Returns a pointer to the
          * first character after it */
 
-        p = strstr(haystack, needle);
+        char *p = (char*) strstr(haystack, needle);
         if (!p)
                 return NULL;
 
@@ -1506,7 +1504,7 @@ ssize_t strlevenshtein(const char *x, const char *y) {
         return t1[yl];
 }
 
-char* strrstr(const char *haystack, const char *needle) {
+char* strrstr_internal(const char *haystack, const char *needle) {
         /* Like strstr() but returns the last rather than the first occurrence of "needle" in "haystack". */
 
         if (!haystack || !needle)
@@ -1515,7 +1513,7 @@ char* strrstr(const char *haystack, const char *needle) {
         /* Special case: for the empty string we return the very last possible occurrence, i.e. *after* the
          * last char, not before. */
         if (*needle == 0)
-                return strchr(haystack, 0);
+                return (char*) strchr(haystack, 0);
 
         for (const char *p = strstr(haystack, needle), *q; p; p = q) {
                 q = strstr(p + 1, needle);
index cc6aa183c0c6e6dde2e247038c2d14d82ac6bde8..3ccc3c2cd041f3d6b92143a43470012e0b025d9f 100644 (file)
 #define URI_UNRESERVED      ALPHANUMERICAL "-._~"       /* [RFC3986] */
 #define URI_VALID           URI_RESERVED URI_UNRESERVED /* [RFC3986] */
 
-static inline char* strstr_ptr(const char *haystack, const char *needle) {
+static inline char* strstr_ptr_internal(const char *haystack, const char *needle) {
         if (!haystack || !needle)
                 return NULL;
-        return strstr(haystack, needle);
+        return (char*) strstr(haystack, needle);
 }
 
-static inline char* strstrafter(const char *haystack, const char *needle) {
-        char *p;
+#define strstr_ptr(haystack, needle) \
+        const_generic(haystack, strstr_ptr_internal(haystack, needle))
 
+static inline char* strstrafter_internal(const char *haystack, const char *needle) {
         /* Returns NULL if not found, or pointer to first character after needle if found */
 
-        p = strstr_ptr(haystack, needle);
+        char *p = (char*) strstr_ptr(haystack, needle);
         if (!p)
                 return NULL;
 
         return p + strlen(needle);
 }
 
+#define strstrafter(haystack, needle) \
+        const_generic(haystack, strstrafter_internal(haystack, needle))
+
 static inline const char* strnull(const char *s) {
         return s ?: "(null)";
 }
@@ -301,7 +305,9 @@ size_t strspn_from_end(const char *str, const char *accept);
 char* strdupspn(const char *a, const char *accept);
 char* strdupcspn(const char *a, const char *reject);
 
-char* find_line_startswith(const char *haystack, const char *needle);
+char* find_line_startswith_internal(const char *haystack, const char *needle);
+#define find_line_startswith(haystack, needle) \
+        const_generic(haystack, find_line_startswith_internal(haystack, needle))
 
 bool version_is_valid(const char *s);
 
@@ -309,4 +315,6 @@ bool version_is_valid_versionspec(const char *s);
 
 ssize_t strlevenshtein(const char *x, const char *y);
 
-char* strrstr(const char *haystack, const char *needle);
+char* strrstr_internal(const char *haystack, const char *needle) _pure_;
+#define strrstr(haystack, needle) \
+        const_generic(haystack, strrstr_internal(haystack, needle))
index a92b1234a3a4e30abc615e4a541fa5236a81664e..58f43acf5ce7493ac6bfc22506fbf863836b2baa 100644 (file)
@@ -881,9 +881,9 @@ int strv_extendf(char ***l, const char *format, ...) {
         return strv_consume(l, x);
 }
 
-char* startswith_strv(const char *s, char * const *l) {
+char* startswith_strv_internal(const char *s, char * const *l) {
         STRV_FOREACH(i, l) {
-                char *found = startswith(s, *i);
+                char *found = (char*) startswith(s, *i);
                 if (found)
                         return found;
         }
@@ -891,9 +891,9 @@ char* startswith_strv(const char *s, char * const *l) {
         return NULL;
 }
 
-char* endswith_strv(const char *s, char * const *l) {
+char* endswith_strv_internal(const char *s, char * const *l) {
         STRV_FOREACH(i, l) {
-                char *found = endswith(s, *i);
+                char *found = (char*) endswith(s, *i);
                 if (found)
                         return found;
         }
index 49ef19dcb5a0358d9159f0788a5c10154be48f02..22bdacf770802e687858ebd098379818b570e6d7 100644 (file)
@@ -171,12 +171,14 @@ static inline void strv_print(char * const *l) {
         strv_print_full(l, NULL);
 }
 
-char* startswith_strv(const char *s, char * const *l);
+char* startswith_strv_internal(const char *s, char * const *l);
+#define startswith_strv(s, l) const_generic(s, startswith_strv_internal(s, l))
 
 #define STARTSWITH_SET(p, ...)                                  \
         startswith_strv(p, STRV_MAKE(__VA_ARGS__))
 
-char* endswith_strv(const char *s, char * const *l);
+char* endswith_strv_internal(const char *s, char * const *l);
+#define endswith_strv(s, l) const_generic(s, endswith_strv_internal(s, l))
 
 #define ENDSWITH_SET(p, ...)                                    \
         endswith_strv(p, STRV_MAKE(__VA_ARGS__))
index 763156b79bd5447dcb0677bc332e1c04e8786645..c6fa17d1d8383c8db8893fb41f831c1009a5a04b 100644 (file)
@@ -1123,9 +1123,7 @@ static const char* extract_multiplier(const char *p, usec_t *ret) {
         assert(ret);
 
         FOREACH_ELEMENT(i, table) {
-                char *e;
-
-                e = startswith(p, i->suffix);
+                const char *e = startswith(p, i->suffix);
                 if (e) {
                         *ret = i->usec;
                         return e;
@@ -1305,9 +1303,7 @@ static const char* extract_nsec_multiplier(const char *p, nsec_t *ret) {
         assert(ret);
 
         FOREACH_ELEMENT(i, table) {
-                char *e;
-
-                e = startswith(p, i->suffix);
+                const char *e = startswith(p, i->suffix);
                 if (e) {
                         *ret = i->nsec;
                         return e;
index 43c15213effe97162da5746e76d754ffa12bf5b3..d5e95ce89c5471e4248ae44a54bc624bbdabcfe8 100644 (file)
@@ -218,7 +218,7 @@ UnitType unit_name_to_type(const char *n) {
 int unit_name_change_suffix(const char *n, const char *suffix, char **ret) {
         _cleanup_free_ char *s = NULL;
         size_t a, b;
-        char *e;
+        const char *e;
 
         assert(n);
         assert(suffix);
@@ -526,7 +526,7 @@ int unit_name_template(const char *f, char **ret) {
 }
 
 bool unit_name_is_hashed(const char *name) {
-        char *s;
+        const char *s;
 
         if (!unit_name_is_valid(name, UNIT_NAME_PLAIN))
                 return false;
@@ -549,7 +549,7 @@ bool unit_name_is_hashed(const char *name) {
 
 int unit_name_hash_long(const char *name, char **ret) {
         _cleanup_free_ char *n = NULL, *hash = NULL;
-        char *suffix;
+        const char *suffix;
         le64_t h;
         size_t len;
 
@@ -839,7 +839,7 @@ int slice_build_subslice(const char *slice, const char *name, char **ret) {
         if (streq(slice, SPECIAL_ROOT_SLICE))
                 subslice = strjoin(name, ".slice");
         else {
-                char *e;
+                const char *e;
 
                 assert_se(e = endswith(slice, ".slice"));
 
index 6a3ff961fc8adbf11d7bb0773c260bcd7fa18382..a6565504bffbd697d1a929a80ec4f956d66ddb2f 100644 (file)
@@ -798,10 +798,9 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
 static int add_crypttab_device(const char *name, const char *device,  const char *keyspec, const char *options) {
         _cleanup_free_ char *keyfile = NULL, *keydev = NULL, *headerdev = NULL, *filtered_header = NULL;
         crypto_device *d = NULL;
-        char *uuid;
         int r;
 
-        uuid = startswith(device, "UUID=");
+        const char *uuid = startswith(device, "UUID=");
         if (!uuid)
                 uuid = path_startswith(device, "/dev/disk/by-uuid/");
         if (!uuid)
index 74c057b294dd66e559afa7f45a668e6d3331e361..68612ea925015e5c357c3b2ba66ae893667f0ba7 100644 (file)
@@ -568,3 +568,10 @@ static inline uint64_t ALIGN_OFFSET_U64(uint64_t l, uint64_t ali) {
 
 #define PTR_TO_SIZE(p) ((size_t) ((uintptr_t) (p)))
 #define SIZE_TO_PTR(u) ((void *) ((uintptr_t) (u)))
+
+/* This macro is used to have a const-returning and non-const returning version of a function based on
+ * whether its first argument is const or not (e.g. strstr()). */
+#define const_generic(ptr, call)                              \
+        _Generic(0 ? (ptr) : (void*) 1,                       \
+                 const void*: (const typeof(*call)*) (call),  \
+                 void*: (call))
index a18b2bc4c9d1494f6ba9c30422e46d36675a053f..2b4c66cfa36aa68955622ac65245b0e663421e74 100644 (file)
@@ -7,7 +7,7 @@
 #include "macro-fundamental.h"
 #include "string-util-fundamental.h"
 
-sd_char *startswith(const sd_char *s, const sd_char *prefix) {
+sd_char *startswith_internal(const sd_char *s, const sd_char *prefix) {
         size_t l;
 
         assert(s);
@@ -20,7 +20,7 @@ sd_char *startswith(const sd_char *s, const sd_char *prefix) {
         return (sd_char*) s + l;
 }
 
-sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) {
+sd_char *startswith_no_case_internal(const sd_char *s, const sd_char *prefix) {
         size_t l;
 
         assert(s);
@@ -33,7 +33,7 @@ sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) {
         return (sd_char*) s + l;
 }
 
-sd_char* endswith(const sd_char *s, const sd_char *suffix) {
+sd_char* endswith_internal(const sd_char *s, const sd_char *suffix) {
         size_t sl, pl;
 
         assert(s);
@@ -54,7 +54,7 @@ sd_char* endswith(const sd_char *s, const sd_char *suffix) {
         return (sd_char*) s + sl - pl;
 }
 
-sd_char* endswith_no_case(const sd_char *s, const sd_char *suffix) {
+sd_char* endswith_no_case_internal(const sd_char *s, const sd_char *suffix) {
         size_t sl, pl;
 
         assert(s);
index 419f1cc3da43e9e9bd036fffb24d4133c9b73a9a..263f2904511a6af7a0f57affd6ea9087a7cd6147 100644 (file)
@@ -57,10 +57,17 @@ static inline size_t strlen_ptr(const sd_char *s) {
         return strlen(s);
 }
 
-sd_char *startswith(const sd_char *s, const sd_char *prefix) _pure_;
-sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) _pure_;
-sd_char *endswith(const sd_char *s, const sd_char *suffix) _pure_;
-sd_char *endswith_no_case(const sd_char *s, const sd_char *suffix) _pure_;
+sd_char *startswith_internal(const sd_char *s, const sd_char *prefix) _pure_;
+#define startswith(s, prefix) const_generic(s, startswith_internal(s, prefix))
+
+sd_char *startswith_no_case_internal(const sd_char *s, const sd_char *prefix) _pure_;
+#define startswith_no_case(s, prefix) const_generic(s, startswith_no_case_internal(s, prefix))
+
+sd_char *endswith_internal(const sd_char *s, const sd_char *suffix) _pure_;
+#define endswith(s, suffix) const_generic(s, endswith_internal(s, suffix))
+
+sd_char *endswith_no_case_internal(const sd_char *s, const sd_char *suffix) _pure_;
+#define endswith_no_case(s, suffix) const_generic(s, endswith_no_case_internal(s, suffix))
 
 static inline bool isempty(const sd_char *a) {
         return !a || a[0] == '\0';
index ce131c553e36fb09040d6dbff226ccf484257a1d..2d9b423eff152a78156f6fbd0016a35d1ebbd8ac 100644 (file)
@@ -826,7 +826,7 @@ static int manager_assess_image(
                 const char *dir_path,
                 const char *dentry_name) {
 
-        char *luks_suffix, *directory_suffix;
+        const char *luks_suffix, *directory_suffix;
         _cleanup_free_ char *path = NULL;
         struct stat st;
         int r;
index 1c6348574c5f0cfead6351c1903eb380c3dc3984..2218303ae4bfe40ff10c3d5453012a918faa363c 100644 (file)
@@ -90,7 +90,7 @@ static int get_possible_units(
                         _cleanup_free_ char *u = NULL;
                         char *eq;
 
-                        eq = memchr(data, '=', size);
+                        eq = (char*) memchr(data, '=', size);
                         if (eq) {
                                 size -= eq - (char*) data + 1;
                                 data = ++eq;
index 3ea12fc3718880022726105f5d25e6b0c8c2df46..ae332c57be9601d3d3dd4748886e40c4ee99de76 100644 (file)
@@ -1437,7 +1437,7 @@ _public_ int sd_bus_open_user(sd_bus **ret) {
 
 int bus_set_address_system_remote(sd_bus *b, const char *host) {
         _cleanup_free_ char *e = NULL;
-        char *m = NULL, *c = NULL, *a, *rbracket = NULL, *p = NULL;
+        const char *m = NULL, *c = NULL, *a, *rbracket = NULL, *p = NULL;
 
         assert(b);
         assert(host);
@@ -1475,7 +1475,7 @@ int bus_set_address_system_remote(sd_bus *b, const char *host) {
         /* Let's see if a port was given */
         m = strchr(rbracket ? rbracket + 1 : host, ':');
         if (m) {
-                char *t;
+                const char *t;
                 bool got_forward_slash = false;
 
                 p = m + 1;
@@ -1521,14 +1521,15 @@ interpret_port_as_machine_old_syntax:
         if (!ssh_escaped)
                 return -ENOMEM;
 
-        a = strjoin("unixexec:path=", ssh_escaped, ",argv1=-xT",
-                    p ? ",argv2=-p,argv3=" : "", strempty(p),
-                    ",argv", p ? "4" : "2", "=--,argv", p ? "5" : "3", "=", e,
-                    ",argv", p ? "6" : "4", "=systemd-stdio-bridge", c);
-        if (!a)
+        char *address = strjoin(
+                        "unixexec:path=", ssh_escaped, ",argv1=-xT",
+                        p ? ",argv2=-p,argv3=" : "", strempty(p),
+                        ",argv", p ? "4" : "2", "=--,argv", p ? "5" : "3", "=", e,
+                        ",argv", p ? "6" : "4", "=systemd-stdio-bridge", c);
+        if (!address)
                 return -ENOMEM;
 
-        return free_and_replace(b->address, a);
+        return free_and_replace(b->address, address);
 }
 
 _public_ int sd_bus_open_system_remote(sd_bus **ret, const char *host) {
index 588fb0313bca7da65d960d38d60683c8352f7c37..a18a8462013fc1babd4e79d8d3de64bf9dd08712 100644 (file)
@@ -97,7 +97,7 @@ static int trie_children_cmp_f(const void *v1, const void *v2) {
 }
 
 static const struct trie_node_f *node_lookup_f(sd_hwdb *hwdb, const struct trie_node_f *node, uint8_t c) {
-        struct trie_child_entry_f *child;
+        const struct trie_child_entry_f *child;
         struct trie_child_entry_f search;
 
         search.c = c;
index 7dcc35d8d5840aff362155637e23167fbaf29620..c676d83003b5666fdb3b65576129badbe44b9776 100644 (file)
@@ -195,20 +195,18 @@ static int finish_item(
 }
 
 int catalog_file_lang(const char* filename, char **lang) {
-        char *beg, *end, *_lang;
-
-        end = endswith(filename, ".catalog");
+        const char *end = endswith(filename, ".catalog");
         if (!end)
                 return 0;
 
-        beg = end - 1;
+        const char *beg = end - 1;
         while (beg > filename && !IN_SET(*beg, '.', '/') && end - beg < 32)
                 beg--;
 
         if (*beg != '.' || end <= beg + 1)
                 return 0;
 
-        _lang = strndup(beg + 1, end - beg - 1);
+        char *_lang = strndup(beg + 1, end - beg - 1);
         if (!_lang)
                 return -ENOMEM;
 
@@ -526,7 +524,8 @@ static int open_mmap(const char *database, int *_fd, struct stat *_st, void **_p
 }
 
 static const char *find_id(void *p, sd_id128_t id) {
-        CatalogItem *f = NULL, key = { .id = id };
+        CatalogItem key = { .id = id };
+        const CatalogItem *f = NULL;
         const CatalogHeader *h = p;
         const char *loc;
 
index c35102af74a5ff97c4cecd3c872b0183e132cb58..2b5da90caa06ad40a667f7f7fd9a9607f9682f2e 100644 (file)
@@ -746,7 +746,6 @@ int config_parse_dhcp_server_relay_agent_suboption(
                 void *userdata) {
 
         char **suboption_value = data;
-        char* p;
 
         assert(filename);
         assert(lvalue);
@@ -757,7 +756,7 @@ int config_parse_dhcp_server_relay_agent_suboption(
                 return 0;
         }
 
-        p = startswith(rvalue, "string:");
+        const char *p = startswith(rvalue, "string:");
         if (!p) {
                 log_syntax(unit, LOG_WARNING, filename, line, 0,
                            "Failed to parse %s=%s'. Invalid format, ignoring.", lvalue, rvalue);
index 06bfb90c8fa5dcb7ea9ce26b4d1d3fef464bee7f..e2ef351301e70c0bb4df708aa0ed277f56194aad 100644 (file)
@@ -1855,14 +1855,14 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
 
         if (streq(field, "RootHashSignature")) {
                 _cleanup_free_ void *roothash_sig_decoded = NULL;
-                char *value;
                 size_t roothash_sig_decoded_size = 0;
 
                 /* We have the path to a roothash signature to load and decode, eg: RootHash=/foo/bar.roothash.p7s */
                 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 RootHashSignature= '%s', not a path but doesn't start with 'base64:'.", eq);
 
                 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
index f1043ec13261cd707b45a397d41b67128205b0e0..64d9069f9b61d70adcacf2d5722094dff81de1c4 100644 (file)
@@ -304,7 +304,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;
index e6a361c82cc90d6b46049698a1895fd6ee3c8d10..7302148376abfe6a56b020576069a292c37c19d2 100644 (file)
@@ -2389,7 +2389,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);
index 4720e7448d8acfedd4492a8a022c1ecbe801ecfb..18264b62d8a8eea52fb31a1901eec52f9f4ec4b2 100644 (file)
@@ -334,7 +334,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)
index 09c04b9a7fefc7b5a884cbc26a983b688d495af4..26ddc101cbea5d9c8c140d4d87ea6288f83cf10a 100644 (file)
@@ -957,7 +957,7 @@ static int names_pci(sd_device *dev, const char *prefix, EventMode mode) {
 }
 
 static int get_usb_specifier(sd_device *dev, char **ret) {
-        char *ports, *config, *interf, *s, *buf;
+        char *ports, *config, *interf, *buf;
         const char *sysname;
         int r;
 
@@ -969,26 +969,26 @@ static int get_usb_specifier(sd_device *dev, char **ret) {
                 return log_device_debug_errno(dev, r, "Failed to get sysname: %m");
 
         /* get USB port number chain, configuration, interface */
-        s = strchr(sysname, '-');
+        const char *s = strchr(sysname, '-');
         if (!s)
                 return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
                                               "sysname \"%s\" does not have '-' in the expected place.", sysname);
 
         ports = strdupa_safe(s + 1);
-        s = strchr(ports, ':');
+        char *t = strchr(ports, ':');
         if (!s)
                 return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
                                               "sysname \"%s\" does not have ':' in the expected place.", sysname);
 
-        *s = '\0';
-        config = s + 1;
+        *t = '\0';
+        config = t + 1;
         s = strchr(config, '.');
         if (!s)
                 return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
                                               "sysname \"%s\" does not have '.' in the expected place.", sysname);
 
-        *s = '\0';
-        interf = s + 1;
+        *t = '\0';
+        interf = t + 1;
 
         /* prefix every port number in the chain with "u" */
         string_replace_char(ports, '.', 'u');