From: Paul Eggert Date: Fri, 1 Nov 2024 16:40:36 +0000 (-0700) Subject: Remove unnecessary casts X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=989842ff0d804aeee852cd53d541c5f5b0b7f223;p=thirdparty%2Ftar.git Remove unnecessary casts 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. --- diff --git a/src/buffer.c b/src/buffer.c index ec0da361..25f0b17e 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -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. */ diff --git a/src/create.c b/src/create.c index fac7c701..bc61c3da 100644 --- a/src/create.c +++ b/src/create.c @@ -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); } diff --git a/src/incremen.c b/src/incremen.c index 5e16238c..2224f0b1 100644 --- a/src/incremen.c +++ b/src/incremen.c @@ -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; diff --git a/src/list.c b/src/list.c index 5ff657e3..f3ab4dd4 100644 --- a/src/list.c +++ b/src/list.c @@ -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 = '-'; diff --git a/src/map.c b/src/map.c index 69d1a688..1a1d0402 100644 --- 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; diff --git a/src/system.c b/src/system.c index 0c668a9f..20891784 100644 --- a/src/system.c +++ b/src/system.c @@ -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); } diff --git a/src/tar.c b/src/tar.c index 66ffd48c..3eb02f43 100644 --- 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; diff --git a/src/utf8.c b/src/utf8.c index 2e499a9c..caa185e3 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -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 diff --git a/src/xattrs.c b/src/xattrs.c index 737eca3d..e2989087 100644 --- a/src/xattrs.c +++ b/src/xattrs.c @@ -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); } diff --git a/src/xheader.c b/src/xheader.c index 91c84805..830740bf 100644 --- a/src/xheader.c +++ b/src/xheader.c @@ -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++ = ' ';