]> 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>
Thu, 27 Nov 2025 15:46:22 +0000 (16:46 +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>
misc-utils/whereis.c

index f705ac278ef6b5c3c3002b06f2230da0b5078e8b..2e2ecda9e988540dc95ead1f50c4417faaef10cf 100644 (file)
@@ -270,7 +270,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, '*');
@@ -474,11 +474,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",