]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
whereis: fix const qualifier warnings for C23
authorKarel Zak <kzak@redhat.com>
Thu, 27 Nov 2025 15:46:22 +0000 (16:46 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 8 Dec 2025 13:48:07 +0000 (14:48 +0100)
Fix const qualifier discarded warnings in dirlist_add_subdir() and
lookup() functions. These warnings are reported by gcc 15 which
defaults to the C23 standard.

The strchr() and strrchr() functions return pointers into const strings,
so the receiving variables must be declared as const char *.

Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit 01018b74163f9122c75179a7c991b0aa0f8c603c)

misc-utils/whereis.c

index b575e57aeea561caad38819ada1cf466231c8142..310512b307bf7fc8ae64fc122d28c8fc13340fdc 100644 (file)
@@ -269,7 +269,7 @@ static void dirlist_add_subdir(struct wh_dirlist **ls, int type, const char *dir
        char buf[PATH_MAX], *d;
        DIR *dirp;
        struct dirent *dp;
-       char *postfix;
+       const char *postfix;
        size_t len;
 
        postfix = strchr(dir, '*');
@@ -473,11 +473,12 @@ static void lookup(const char *pattern, struct wh_dirlist *ls, int want)
 {
        char patbuf[PATH_MAX] = { 0 };
        int count = 0;
-       char *wait = NULL, *p;
+       char *wait = NULL;
+       const char *p;
 
        /* canonicalize pattern -- remove path suffix etc. */
        p = strrchr(pattern, '/');
-       p = p ? p + 1 : (char *) pattern;
+       p = p ? p + 1 : pattern;
        xstrncpy(patbuf, p, PATH_MAX);
 
        DBG(SEARCH, ul_debug("lookup dirs for '%s' (%s), want: %s %s %s",