]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix const qualifier warning in mnt_parse_mountinfo_line
authorKarel Zak <kzak@redhat.com>
Thu, 27 Nov 2025 15:24:11 +0000 (16:24 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 27 Nov 2025 15:24:11 +0000 (16:24 +0100)
Fix const qualifier discarded warning in mnt_parse_mountinfo_line().
This warning is reported by gcc 15 which defaults to the C23 standard.

The strstr() function returns a pointer into a const string, so
introduce a separate 'sep' variable to hold this const pointer,
keeping 'p' for non-const unmangle() results that need to be freed.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/tab_parse.c

index bd15ad90985ca8e98df36bca31a71ecb8810dd03..7ec4c401635a471716daf48afa59d005b625ab3b 100644 (file)
@@ -186,6 +186,7 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, const char *s)
        int rc = 0;
        unsigned int maj, min;
        char *p;
+       const char *sep;
 
        fs->flags |= MNT_FS_KERNEL;
        mnt_fs_mark_attached(fs);
@@ -243,15 +244,15 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, const char *s)
        }
 
        /* (7) optional fields, terminated by " - " */
-       p = strstr(s, " - ");
-       if (!p) {
+       sep = strstr(s, " - ");
+       if (!sep) {
                DBG(TAB, ul_debug("mountinfo parse error: separator not found"));
                return -EINVAL;
        }
-       if (p > s + 1)
-               fs->opt_fields = strndup(s + 1, p - s - 1);
+       if (sep > s + 1)
+               fs->opt_fields = strndup(s + 1, sep - s - 1);
 
-       s = skip_separator(p + 3);
+       s = skip_separator(sep + 3);
 
        /* (8) FS type */
        p = unmangle(s, &s);