]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Remove unnecessary casts
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 2 Nov 2024 06:47:23 +0000 (23:47 -0700)
Some of these date back to pre-C89.
* src/buffer.c (backspace_output):
* src/create.c (to_base256, gid_to_chars, major_to_chars)
(minor_to_chars, off_to_chars, time_to_chars, uid_to_chars):
* src/list.c (from_header, tartime):
* src/map.c (owner_map_translate, group_map_translate):
* src/system.c (sys_truncate):
* src/utf8.c (utf8_init):
* src/xattrs.c (acls_one_line):
* src/xheader.c (xheader_string_end):
Remove casts.
* src/create.c (uintmax_to_chars): Remove.  All uses removed.
(simple_finish_header): Use to_octal.

src/buffer.c
src/create.c
src/incremen.c
src/list.c
src/map.c
src/system.c
src/tar.c
src/utf8.c
src/xattrs.c
src/xheader.c

index ec0da361a38e4341eaea927a977fec5910ad1c9e..25f0b17ec17c0e81565557427848ac1eb2dd5da7 100644 (file)
@@ -1066,7 +1066,7 @@ backspace_output (void)
     return;
 
   {
-    off_t position = rmtlseek (archive, (off_t) 0, SEEK_CUR);
+    off_t position = rmtlseek (archive, 0, SEEK_CUR);
 
     /* Seek back to the beginning of this record and start writing there.  */
 
index fac7c7014a581f5288ce1bedc7ffa12ba72d3bff..bc61c3daedcd1bb66888648d1d81cc4de348d492 100644 (file)
@@ -187,8 +187,8 @@ static void
 to_base256 (bool negative, uintmax_t value, char *where, idx_t size)
 {
   uintmax_t v = value;
-  uintmax_t propagated_sign_bits =
-    ((uintmax_t) - negative << (UINTMAX_WIDTH - LG_256));
+  uintmax_t sign_bits = - negative;
+  uintmax_t propagated_sign_bits = sign_bits << (UINTMAX_WIDTH - LG_256);
   idx_t i = size;
 
   do
@@ -342,19 +342,19 @@ gid_substitute (bool *negative)
 static bool
 gid_to_chars (gid_t v, char *p, idx_t s)
 {
-  return to_chars (v < 0, (uintmax_t) v, sizeof v, gid_substitute, p, s, "gid_t");
+  return to_chars (v < 0, v, sizeof v, gid_substitute, p, s, "gid_t");
 }
 
 static bool
 major_to_chars (major_t v, char *p, idx_t s)
 {
-  return to_chars (v < 0, (uintmax_t) v, sizeof v, 0, p, s, "major_t");
+  return to_chars (v < 0, v, sizeof v, 0, p, s, "major_t");
 }
 
 static bool
 minor_to_chars (minor_t v, char *p, idx_t s)
 {
-  return to_chars (v < 0, (uintmax_t) v, sizeof v, 0, p, s, "minor_t");
+  return to_chars (v < 0, v, sizeof v, 0, p, s, "minor_t");
 }
 
 static bool
@@ -400,13 +400,13 @@ mode_to_chars (mode_t v, char *p, idx_t s)
 bool
 off_to_chars (off_t v, char *p, idx_t s)
 {
-  return to_chars (v < 0, (uintmax_t) v, sizeof v, 0, p, s, "off_t");
+  return to_chars (v < 0, v, sizeof v, 0, p, s, "off_t");
 }
 
 bool
 time_to_chars (time_t v, char *p, idx_t s)
 {
-  return to_chars (v < 0, (uintmax_t) v, sizeof v, 0, p, s, "time_t");
+  return to_chars (v < 0, v, sizeof v, 0, p, s, "time_t");
 }
 
 static uintmax_t
@@ -428,13 +428,7 @@ uid_substitute (bool *negative)
 static bool
 uid_to_chars (uid_t v, char *p, idx_t s)
 {
-  return to_chars (v < 0, (uintmax_t) v, sizeof v, uid_substitute, p, s, "uid_t");
-}
-
-static bool
-uintmax_to_chars (uintmax_t v, char *p, idx_t s)
-{
-  return to_chars (false, v, sizeof v, 0, p, s, "uintmax_t");
+  return to_chars (v < 0, v, sizeof v, uid_substitute, p, s, "uid_t");
 }
 
 static void
@@ -970,9 +964,10 @@ simple_finish_header (union block *header)
 
      This is a fast way to do:
 
-     sprintf(header->header.chksum, "%6o", sum);  */
+     sprintf (header->header.chksum, "%6o", sum);  */
 
-  uintmax_to_chars ((uintmax_t) sum, header->header.chksum, 7);
+  header->header.chksum[6] = '\0';
+  to_octal (sum, header->header.chksum, 6);
 
   set_next_block_after (header);
 }
index 5e16238c1debbb02aa2fbc789b482fd7b27fdd52..2224f0b1a43bc05b31f5a1f675068f0abd2c67ce 100644 (file)
@@ -142,7 +142,7 @@ dumpdir_create0 (const char *contents, const char *cmask)
        i++;
     }
   dump = xmalloc (sizeof (*dump) + ctsize);
-  dump->contents = (char*)(dump + 1);
+  dump->contents = (char *) (dump + 1);
   memcpy (dump->contents, contents, ctsize);
   dump->total = total;
   dump->elc = i;
index 5ff657e300ffcb1e2d9d2ded282e0abcae8aa836..f3ab4dd463e70bad4552f00d5ee076397520ec24 100644 (file)
@@ -802,11 +802,15 @@ from_header (char const *where0, idx_t digs, char const *type,
          if (!overflow && value <= minus_minval)
            {
              if (!silent)
-               paxwarn (0,
-                        /* TRANSLATORS: Second %s is a type name (gid_t,uid_t,etc.) */
-                        _("Archive octal value %.*s is out of %s range;"
-                          " assuming two's complement"),
-                        (int) (where - where1), where1, type);
+               {
+                 int width = where - where1;
+                 paxwarn (0,
+                          /* TRANSLATORS: Second %s is a type name
+                             (gid_t, uid_t, etc.).  */
+                          _("Archive octal value %.*s is out of %s range;"
+                            " assuming two's complement"),
+                          width, where1, type);
+               }
              negative = true;
            }
        }
@@ -814,10 +818,14 @@ from_header (char const *where0, idx_t digs, char const *type,
       if (overflow)
        {
          if (type && !silent)
-           paxerror (0,
-                     /* TRANSLATORS: Second %s is a type name (gid_t,uid_t,etc.) */
-                     _("Archive octal value %.*s is out of %s range"),
-                     (int) (where - where1), where1, type);
+           {
+             int width = where - where1;
+             paxerror (0,
+                       /* TRANSLATORS: Second %s is a type name
+                          (gid_t, uid_t, etc.).  */
+                       _("Archive octal value %.*s is out of %s range"),
+                       width, where1, type);
+           }
          return -1;
        }
     }
@@ -849,7 +857,8 @@ from_header (char const *where0, idx_t digs, char const *type,
          if (ckd_mul (&value, value, 64))
            {
              if (type && !silent)
-               paxerror (0, _("Archive signed base-64 string %s is out of %s range"),
+               paxerror (0, _("Archive signed base-64 string %s"
+                              " is out of %s range"),
                          quote_mem (where0, digs), type);
              return -1;
            }
@@ -868,8 +877,8 @@ from_header (char const *where0, idx_t digs, char const *type,
         always on, so that we don't confuse this format with the
         others (assuming ASCII bytes of 8 bits or more).  */
       int signbit = *where & (1 << (LG_256 - 2));
-      uintmax_t topbits = (((uintmax_t) - signbit)
-                          << (UINTMAX_WIDTH - LG_256 - (LG_256 - 2)));
+      uintmax_t signbits = - signbit;
+      uintmax_t topbits = signbits << (UINTMAX_WIDTH - LG_256 - (LG_256 - 2));
       value = (*where++ & ((1 << (LG_256 - 2)) - 1)) - signbit;
       for (;;)
        {
@@ -880,7 +889,8 @@ from_header (char const *where0, idx_t digs, char const *type,
          if (((value << LG_256 >> LG_256) | topbits) != value)
            {
              if (type && !silent)
-               paxerror (0, _("Archive base-256 value is out of %s range"), type);
+               paxerror (0, _("Archive base-256 value is out of %s range"),
+                         type);
              return -1;
            }
        }
@@ -894,6 +904,7 @@ from_header (char const *where0, idx_t digs, char const *type,
       if (type)
        {
          char buf[1000]; /* Big enough to represent any header.  */
+         int bufsize = sizeof buf;
          static struct quoting_options *o;
 
          if (!o)
@@ -907,9 +918,11 @@ from_header (char const *where0, idx_t digs, char const *type,
          quotearg_buffer (buf, sizeof buf, where0, lim - where0, o);
          if (!silent)
            paxerror (0,
-                     /* TRANSLATORS: Second %s is a type name (gid_t,uid_t,etc.) */
-                     _("Archive contains %.*s where numeric %s value expected"),
-                     (int) sizeof buf, buf, type);
+                     /* TRANSLATORS: Second %s is a type name
+                        (gid_t, uid_t, etc.).  */
+                     _("Archive contains %.*s"
+                       " where numeric %s value expected"),
+                     bufsize, buf, type);
        }
 
       return -1;
@@ -1045,7 +1058,9 @@ tartime (struct timespec t, bool full_time)
      is out of range.  Convert it as an integer,
      right-adjusted in a field with the same width as the usual
      4-year ISO time format.  */
-  p = umaxtostr (negative ? - (uintmax_t) s : s,
+
+  uintmax_t us = s;
+  p = umaxtostr (negative ? - us : s,
                 buffer + sizeof buffer - UINTMAX_STRSIZE_BOUND - fraclen);
   if (negative)
     *--p = '-';
index 69d1a688f216db5338a60bb22ea6a16ee8fe4250..1a1d0402dda37b327e9a0a95bac1d179447b6cb9 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -216,7 +216,8 @@ owner_map_translate (uid_t uid, uid_t *new_uid, char const **new_name)
        }
     }
 
-  if (owner_option != (uid_t) -1)
+  uid_t minus_1 = -1;
+  if (owner_option != minus_1)
     {
       *new_uid = owner_option;
       rc = 0;
@@ -266,7 +267,8 @@ group_map_translate (gid_t gid, gid_t *new_gid, char const **new_name)
        }
     }
 
-  if (group_option != (uid_t) -1)
+  gid_t minus_1 = -1;
+  if (group_option != minus_1)
     {
       *new_gid = group_option;
       rc = 0;
index 0c668a9f7dae8e3852983af223d25e868a5de42d..208917848b7a37df0c6dad0ade1b7eb1e5eee7ac 100644 (file)
@@ -289,7 +289,7 @@ sys_compare_links (struct stat *link_data, struct stat *stat_data)
 int
 sys_truncate (int fd)
 {
-  off_t pos = lseek (fd, (off_t) 0, SEEK_CUR);
+  off_t pos = lseek (fd, 0, SEEK_CUR);
   return pos < 0 ? -1 : ftruncate (fd, pos);
 }
 
index 66ffd48c7751a456db34df0df26e1cb92771a588..3eb02f435cf994598d43e9ee1b6073a06b31013a 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -1222,7 +1222,7 @@ tar_help_filter (int key, const char *text, MAYBE_UNUSED void *input)
   switch (key)
     {
     default:
-      s = (char*) text;
+      s = (char *) text;
       break;
 
     case 'j':
@@ -2239,7 +2239,7 @@ static struct argp argp = {
 void
 usage (int status)
 {
-  argp_help (&argp, stderr, ARGP_HELP_SEE, (char*) program_name);
+  argp_help (&argp, stderr, ARGP_HELP_SEE, (char *) program_name);
   close_stdout ();
   exit (status);
 }
@@ -2347,7 +2347,7 @@ parse_default_options (struct tar_args *args)
   if (ws.ws_wordc)
     {
       int idx;
-      ws.ws_wordv[0] = (char*) program_name;
+      ws.ws_wordv[0] = (char *) program_name;
       save_loc_ptr = args->loc;
       args->loc = &loc;
       int argc;
index 2e499a9c5aedc5267aa3d672479bc0eda5c26b0c..caa185e3105da2604bf3a7850e37858831ccbdf1 100644 (file)
@@ -54,14 +54,14 @@ static iconv_t conv_desc[2] = { (iconv_t) -1, (iconv_t) -1 };
 static iconv_t
 utf8_init (bool to_utf)
 {
-  if (conv_desc[(int) to_utf] == (iconv_t) -1)
+  if (conv_desc[to_utf] == (iconv_t) -1)
     {
       if (to_utf)
-       conv_desc[(int) to_utf] = iconv_open ("UTF-8", locale_charset ());
+       conv_desc[to_utf] = iconv_open ("UTF-8", locale_charset ());
       else
-       conv_desc[(int) to_utf] = iconv_open (locale_charset (), "UTF-8");
+       conv_desc[to_utf] = iconv_open (locale_charset (), "UTF-8");
     }
-  return conv_desc[(int) to_utf];
+  return conv_desc[to_utf];
 }
 
 bool
index 737eca3d869d4c862db29af5cc082bb09168b0ea..e29890877cfecc42149640d1fc53ebd703af017e 100644 (file)
@@ -434,7 +434,7 @@ acls_one_line (const char *prefix, char delim,
 
   obstack_1grow (&stk, '\0');
 
-  fprintf (stdlis, "%s", (char *) obstack_finish (&stk));
+  fputs (obstack_finish (&stk), stdlis);
 
   obstack_free (&stk, NULL);
 }
index 91c84805f140b98684160540c618c075f24ed44c..830740bf8f1a7784ed3c0e6fe13737cd59fc6a07 100644 (file)
@@ -935,7 +935,6 @@ xheader_string_end (struct xheader *xhdr, char const *keyword)
   uintmax_t n = 0;
   char nbuf[UINTMAX_STRSIZE_BOUND];
   char const *np;
-  char *cp;
 
   if (xhdr->buffer)
     return false;
@@ -964,7 +963,8 @@ xheader_string_end (struct xheader *xhdr, char const *keyword)
     }
   x_obstack_blank (xhdr, p);
   x_obstack_1grow (xhdr, '\n');
-  cp = (char*) obstack_next_free (xhdr->stk) - xhdr->string_length - p - 1;
+  char *cp = obstack_next_free (xhdr->stk);
+  cp -= xhdr->string_length + p + 1;
   memmove (cp + p, cp, xhdr->string_length);
   cp = stpcpy (cp, np);
   *cp++ = ' ';