]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: cut: avoid discarded-qualifiers warnings
authorPádraig Brady <P@draigBrady.com>
Tue, 7 Apr 2026 13:35:25 +0000 (14:35 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 7 Apr 2026 13:57:18 +0000 (14:57 +0100)
Seen on GCC 15.2.1 with GLIBC 2.43 on Arch
Not seen on GCC 15.2.1 on GLIBC 2.42 on Fedora

* src/cut.c (search_bytes): Cast the return from memchr()
to avoid const propagation.
(find_field_delim): Adjust the return from strstr() similarly.
https://github.com/coreutils/coreutils/issues/244

src/cut.c

index eb82c04494bf0f914865513925559e7c0d208f72..6fa4d0727ef822f75667364d3e472a808e331f0b 100644 (file)
--- a/src/cut.c
+++ b/src/cut.c
@@ -437,7 +437,7 @@ search_bytes (char const *buf, int c, size_t n_bytes)
   if (1 < n_bytes && to_uchar (buf[1]) == c)
     return (char *) buf + 1;
 
-  return 2 < n_bytes ? memchr (buf + 2, c, n_bytes - 2) : NULL;
+  return 2 < n_bytes ? (char *) memchr (buf + 2, c, n_bytes - 2) : NULL;
 }
 
 static inline void
@@ -598,18 +598,18 @@ find_field_delim (char *buf, size_t len)
       char const *nul = memchr (p, '\0', end - p);
       if (!nul)
         {
-          char *match = strstr (p, delim_bytes);
+          char const *match = strstr (p, delim_bytes);
           buf[len] = saved;
-          return match;
+          return (char *) match;
         }
 
       if (p < nul)
         {
-          char *match = strstr (p, delim_bytes);
+          char const *match = strstr (p, delim_bytes);
           if (match)
             {
               buf[len] = saved;
-              return match;
+              return (char *) match;
             }
         }