]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: pacify GCC 16 -Wuseless-cast
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 11 May 2026 06:29:05 +0000 (23:29 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 11 May 2026 06:42:26 +0000 (23:42 -0700)
This mostly either removes casts if they are always no-ops, or
replaces casts (TYPE)(EXPR) with compound literals (TYPE){EXPR}.
Compound literals are a bit safer anyway, as casts are too
powerful in C.
* src/cksum_avx2.c (cksum_avx2):
* src/cksum_avx512.c (cksum_avx512):
* src/cksum_crc.c (cksum_slice8):
* src/cksum_pclmul.c (cksum_pclmul):
* src/cp-hash.c (remember_copied):
* src/numfmt.c (simple_strtod_float):
* src/system.h (x_timestyle_match):
Omit no-op casts.
* src/cp-hash.c (src_to_dest_hash):
* src/dd.c (dd_copy):
* src/df.c (devlist_hash):
* src/env.c (splitbuf_append_byte):
* src/getlimits.c (print_int, main):
* src/ls.c (dev_ino_hash):
* src/truncate.c (do_ftruncate):
Replace casts with compound literals.
* src/factor.c: Ignore -Wuseless-cast, as we include the imported
longlong.h file, which has many of them.
* src/numfmt.c (powerld): 2nd arg is now ptrdiff_t, not int, so
that integers are not silently mishandled in outlandish cases.

14 files changed:
src/cksum_avx2.c
src/cksum_avx512.c
src/cksum_crc.c
src/cksum_pclmul.c
src/cp-hash.c
src/dd.c
src/df.c
src/env.c
src/factor.c
src/getlimits.c
src/ls.c
src/numfmt.c
src/system.h
src/truncate.c

index fe157b508ba75eb33f1a5c8e3b15ca630ef17c15..eea8e073aa3d3ba1aa6a74898682fcbd032d6f9a 100644 (file)
@@ -74,7 +74,7 @@ cksum_avx2 (FILE *fp, uint_fast32_t *crc_out, intmax_t *length_out)
           return false;
         }
 
-      datap = (__m256i *)buf;
+      datap = buf;
 
       /* Fold in parallel 16x 16-byte blocks into 8x 16-byte blocks */
       if (bytes_read >= 16 * 8 * 2)
index 9ac06c63f10cf0a55dbc62b0352deec37cd98932..cc130232153e0422cb65aa7b2c155590e2297a85 100644 (file)
@@ -81,7 +81,7 @@ cksum_avx512 (FILE *fp, uint_fast32_t *crc_out, intmax_t *length_out)
           return false;
         }
 
-      datap = (__m512i *)buf;
+      datap = buf;
 
       /* Fold in parallel 32x 16-byte blocks into 16x 16-byte blocks */
       if (bytes_read >= 16 * 8 * 4)
index de93c1bf55ae0acaa9e9ba5150c92f9561217b3c..dbe2b994f9eb408a9853ee660f065be5686fd98e 100644 (file)
@@ -244,7 +244,7 @@ cksum_slice8 (FILE *fp, uint_fast32_t *crc_out, intmax_t *length_out)
         }
 
       /* Process multiples of 8 bytes */
-      datap = (uint32_t *)buf;
+      datap = buf;
       while (bytes_read >= 8)
         {
           uint32_t first = *datap++, second = *datap++;
index f8860c19baba5c05ff82540b8a07372b35c0e13b..a3a83b282962a503472196432fafa284577239ec 100644 (file)
@@ -72,7 +72,7 @@ cksum_pclmul (FILE *fp, uint_fast32_t *crc_out, intmax_t *length_out)
           return false;
         }
 
-      datap = (__m128i *)buf;
+      datap = buf;
 
       /* Fold in parallel eight 16-byte blocks into four 16-byte blocks */
       if (bytes_read >= 16 * 8)
index 1d5159838a1b28f6599f9bbb11bf14dd4a05833a..80d4b00b4e04f2e1b83a63be0ed0fd20a3045a63 100644 (file)
@@ -55,7 +55,7 @@ src_to_dest_hash (void const *x, size_t table_size)
   /* Ignoring the device number here should be fine.  */
   /* The cast to uintmax_t prevents negative remainders
      if st_ino is negative.  */
-  return (uintmax_t) p->st_ino % table_size;
+  return (uintmax_t) {p->st_ino} % table_size;
 }
 
 /* Compare two Src_to_dest entries.
@@ -135,7 +135,7 @@ remember_copied (char const *name, ino_t ino, dev_t dev)
   if (ent_from_table != ent)
     {
       src_to_dest_free (ent);
-      return (char *) ent_from_table->name;
+      return ent_from_table->name;
     }
 
   /* New key;  insertion succeeded.  */
index 72dcef1683d6165729be58f9a5102ac8c7d60b72..26382a233b6ac7561a915b6a24e259f9a045b07a 100644 (file)
--- a/src/dd.c
+++ b/src/dd.c
@@ -2376,7 +2376,7 @@ dd_copy (void)
                 {
                   diagnose (errno, _("failed to truncate to %jd bytes"
                                      " in output file %s"),
-                            (intmax_t) output_offset, quoteaf (output_file));
+                            (intmax_t) {output_offset}, quoteaf (output_file));
                   return EXIT_FAILURE;
                 }
             }
index f41ba3a870ff0dad1e999d5efe7de1309972f2c8..b3d83f505a6706a041556e3db37d43fb26dfed4c 100644 (file)
--- a/src/df.c
+++ b/src/df.c
@@ -667,7 +667,7 @@ static size_t
 devlist_hash (void const *x, size_t table_size)
 {
   struct devlist const *p = x;
-  return (uintmax_t) p->dev_num % table_size;
+  return (uintmax_t) {p->dev_num} % table_size;
 }
 
 static bool
index 583f7e12b31d4b64e82e24529acbb4f1ce44e14c..3e4f9b3fca3726b6758931c47cb66fdbdec406bc 100644 (file)
--- a/src/env.c
+++ b/src/env.c
@@ -304,7 +304,7 @@ splitbuf_append_byte (struct splitbuf *ss, char c)
   if (ss->half_alloc * sizeof *ss->argv <= string_bytes)
     splitbuf_grow (ss);
   ((char *) (ss->argv + ss->half_alloc))[string_bytes] = c;
-  ss->argv[ss->argc] = (char *) (intptr_t) (string_bytes + 1);
+  ss->argv[ss->argc] = (char *) (intptr_t) {string_bytes + 1};
 }
 
 /* If SS's most recent character was a separator, finish off its
index 06f7b31a23f847f4de5ee8a5784327c548c569b2..e9c37320728b0494e879f3c4d9b2189582d3226c 100644 (file)
@@ -175,6 +175,11 @@ typedef uint64_t UDItype;
 # if defined ASSERT || defined __GMP_DECLSPEC || defined __GMP_GNUC_PREREQ
 # endif
 
+/* longlong.h uses casts even when useless.  */
+# if 14 <= __GNUC__
+#  pragma GCC diagnostic ignored "-Wuseless-cast"
+# endif
+
 # if _ARCH_PPC
 #  define HAVE_HOST_CPU_FAMILY_powerpc 1
 # endif
index 86224a3d0b3cb6ad7065d7e45ea6511d457ad396..514dd3c09e97f9f5d333f9b8ed12fd99c01cf394 100644 (file)
@@ -159,12 +159,12 @@ main (int argc, char **argv)
                                    (char const *) NULL);
 
 #define print_int(TYPE)                                                  \
-  sprintf (limit + 1, "%ju", (uintmax_t) TYPE##_MAX);               \
+  sprintf (limit + 1, "%ju", (uintmax_t) {TYPE##_MAX});                  \
   printf (#TYPE"_MAX=%s\n", limit + 1);                                  \
   printf (#TYPE"_OFLOW=%s\n", decimal_absval_add_one (limit));           \
   if (TYPE##_MIN)                                                        \
     {                                                                    \
-      sprintf (limit + 1, "%jd", (intmax_t) TYPE##_MIN);            \
+      sprintf (limit + 1, "%jd", (intmax_t) {TYPE##_MIN});               \
       printf (#TYPE"_MIN=%s\n", limit + 1);                              \
       printf (#TYPE"_UFLOW=%s\n", decimal_absval_add_one (limit));       \
     }
@@ -199,9 +199,9 @@ main (int argc, char **argv)
   print_float (LDBL);
 
   /* Other useful constants */
-  printf ("SIGRTMIN=%jd\n", (intmax_t) SIGRTMIN);
-  printf ("SIGRTMAX=%jd\n", (intmax_t) SIGRTMAX);
-  printf ("IO_BUFSIZE=%ju\n", (uintmax_t) IO_BUFSIZE);
+  printf ("SIGRTMIN=%jd\n", (intmax_t) {SIGRTMIN});
+  printf ("SIGRTMAX=%jd\n", (intmax_t) {SIGRTMAX});
+  printf ("IO_BUFSIZE=%ju\n", (uintmax_t) {IO_BUFSIZE});
 
   /* Errnos */
   errno_iterate (print_errno, NULL);
index 394e7d26706b7f7ce057e96b1a49fe048a5a548b..3d583b85f153dc38faf1c4dee153476ce920cece 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -1425,7 +1425,7 @@ static size_t
 dev_ino_hash (void const *x, size_t table_size)
 {
   struct dev_ino const *p = x;
-  return (uintmax_t) p->st_ino % table_size;
+  return (uintmax_t) {p->st_ino} % table_size;
 }
 
 static bool
index b4d6d4777003a4cead30bdf9f1371716efb047fd..467e5d79be336c62ebdfab02f61d2e3e1ef1da45 100644 (file)
@@ -330,7 +330,7 @@ suffix_power_char (int power)
 
 /* Similar to 'powl(3)' but without requiring 'libm'.  */
 static long double
-powerld (long double base, int x)
+powerld (long double base, ptrdiff_t x)
 {
   long double result = base;
   if (x == 0)
@@ -588,9 +588,9 @@ simple_strtod_float (char const *input_str,
         return SSE_INVALID_NUMBER;
 
       /* number of digits in the fractions.  */
-      size_t exponent = ptr2 - *endptr;
+      ptrdiff_t exponent = ptr2 - *endptr;
 
-      val_frac = ((long double) val_frac) / powerld (10, exponent);
+      val_frac /= powerld (10, exponent);
 
       /* TODO: detect loss of precision (only really 18 digits
          of precision across all digits (before and after '.')).  */
index 545377335f29ff43409d41294ffd920bbf9aee12..d0f2e0c44d5823e0f3783cfbef2a1231e22b2451 100644 (file)
@@ -1007,7 +1007,7 @@ x_timestyle_match (char const * style, bool allow_posix,
                    int fail_status)
 {
   ptrdiff_t res = argmatch (style, timestyle_args,
-                            (char const *) timestyle_types,
+                            timestyle_types,
                             timestyle_types_size);
   if (res < 0)
     {
index 77133382efefc53306195fb42c749ab63e39c2ad..7119132e06aaafe9fd4e30b535fcff1f4bdccf57 100644 (file)
@@ -190,7 +190,7 @@ do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize,
   if (ftruncate (fd, nsize) != 0)
     {
       error (0, errno, _("failed to truncate %s at %jd bytes"),
-             quoteaf (fname), (intmax_t) nsize);
+             quoteaf (fname), (intmax_t) {nsize});
       return false;
     }