1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-08-18 01:18:51 +02:00

maint: pacify GCC 16 -Wuseless-cast

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.
This commit is contained in:
Paul Eggert
2026-05-10 23:29:05 -07:00
parent f77f365ef5
commit 834ea48535
14 changed files with 25 additions and 20 deletions
+1 -1
View 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)
+1 -1
View 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)
+1 -1
View 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++;
+1 -1
View 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)
+2 -2
View 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. */
+1 -1
View File
@@ -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;
}
}
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+5
View 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
+5 -5
View 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);
+1 -1
View File
@@ -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
+3 -3
View 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 '.')). */
+1 -1
View 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)
{
+1 -1
View 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;
}