Skip to content

Commit

Permalink
Fix a handful of compiler warnings
Browse files Browse the repository at this point in the history
This removes redundant includes, casts, and return statements.
  • Loading branch information
AtariDreams committed Jul 21, 2023
1 parent bd074c2 commit 2218fe1
Show file tree
Hide file tree
Showing 32 changed files with 81 additions and 89 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ MACRO(CHECK_ICONV LIB TRY_ICONV_CONST)
ENDIF(HAVE_ICONV_${LIB}_${TRY_ICONV_CONST})
CMAKE_POP_CHECK_STATE() # Restore the state of the variables
ENDIF(NOT HAVE_ICONV)
ENDMACRO(CHECK_ICONV TRY_ICONV_CONST)
ENDMACRO()

IF(ENABLE_ICONV)
CMAKE_PUSH_CHECK_STATE() # Save the state of the variables
Expand Down
1 change: 0 additions & 1 deletion contrib/archivetest.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ int main(int argc, char *argv[])
v_print(v, "skipping");
} else {
while ((r = archive_read_data(a, buffer, 4096) > 0))
;
if (r == ARCHIVE_FATAL) {
v_print(v, "ERROR\nError string: %s\n",
archive_error_string(a));
Expand Down
6 changes: 3 additions & 3 deletions examples/minitar/minitar.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,19 +408,19 @@ static int
copy_data(struct archive *ar, struct archive *aw)
{
int r;
const void *buff;
const void *buffer;
size_t size;
int64_t offset;

for (;;) {
r = archive_read_data_block(ar, &buff, &size, &offset);
r = archive_read_data_block(ar, &buffer, &size, &offset);
if (r == ARCHIVE_EOF)
return (ARCHIVE_OK);
if (r != ARCHIVE_OK) {
errmsg(archive_error_string(ar));
return (r);
}
r = archive_write_data_block(aw, buff, size, offset);
r = archive_write_data_block(aw, buffer, size, offset);
if (r != ARCHIVE_OK) {
errmsg(archive_error_string(ar));
return (r);
Expand Down
2 changes: 1 addition & 1 deletion libarchive/archive_cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ get_argument(struct archive_string *as, const char *p)
archive_string_empty(as);

/* Skip beginning space characters. */
while (*s != '\0' && *s == ' ')
while (*s == ' ')
s++;
/* Copy non-space characters. */
while (*s != '\0' && *s != ' ') {
Expand Down
19 changes: 9 additions & 10 deletions libarchive/archive_disk_acl_darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ static const acl_perm_map_t acl_nfs4_perm_map[] = {
#endif
};

static const int acl_nfs4_perm_map_size =
(int)(sizeof(acl_nfs4_perm_map)/sizeof(acl_nfs4_perm_map[0]));
static const size_t acl_nfs4_perm_map_size =
(sizeof(acl_nfs4_perm_map) / sizeof(acl_nfs4_perm_map[0]));

static const acl_perm_map_t acl_nfs4_flag_map[] = {
{ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACL_ENTRY_INHERITED},
Expand All @@ -87,8 +87,8 @@ static const acl_perm_map_t acl_nfs4_flag_map[] = {
{ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_ONLY_INHERIT}
};

static const int acl_nfs4_flag_map_size =
(int)(sizeof(acl_nfs4_flag_map)/sizeof(acl_nfs4_flag_map[0]));
static const size_t acl_nfs4_flag_map_size =
(sizeof(acl_nfs4_flag_map) / sizeof(acl_nfs4_flag_map[0]));

static int translate_guid(struct archive *a, acl_entry_t acl_entry,
int *ae_id, int *ae_tag, const char **ae_name)
Expand Down Expand Up @@ -124,7 +124,7 @@ static void
add_trivial_nfs4_acl(struct archive_entry *entry)
{
mode_t mode;
int i;
size_t i;
const int rperm = ARCHIVE_ENTRY_ACL_READ_DATA;
const int wperm = ARCHIVE_ENTRY_ACL_WRITE_DATA |
ARCHIVE_ENTRY_ACL_APPEND_DATA;
Expand Down Expand Up @@ -195,15 +195,13 @@ add_trivial_nfs4_acl(struct archive_entry *entry)
} else if ((mode & 0010) || (mode & 0001))
tacl_entry[1].permset |= eperm;

for (i = 0; i < 6; i++) {
for (i = 0; i < sizeof(tacl_entry) / sizeof(tacl_entry[0]); i++) {
if (tacl_entry[i].permset != 0) {
archive_entry_acl_add_entry(entry,
tacl_entry[i].type, tacl_entry[i].permset,
tacl_entry[i].tag, -1, NULL);
}
}

return;
}

static int
Expand All @@ -214,8 +212,9 @@ translate_acl(struct archive_read_disk *a,
acl_flagset_t acl_flagset;
acl_entry_t acl_entry;
acl_permset_t acl_permset;
int i, entry_acl_type;
int entry_acl_type;
int r, s, ae_id, ae_tag, ae_perm;
size_t i;
const char *ae_name;

s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry);
Expand Down Expand Up @@ -333,7 +332,7 @@ set_acl(struct archive *a, int fd, const char *name,
gid_t ae_gid;
const char *ae_name;
int entries;
int i;
size_t i;

ret = ARCHIVE_OK;
entries = archive_acl_reset(abstract_acl, ae_requested_type);
Expand Down
15 changes: 8 additions & 7 deletions libarchive/archive_disk_acl_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ static const acl_perm_map_t acl_nfs4_perm_map[] = {
{ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACL_SYNCHRONIZE}
};

static const int acl_nfs4_perm_map_size =
(int)(sizeof(acl_nfs4_perm_map)/sizeof(acl_nfs4_perm_map[0]));
static const size_t acl_nfs4_perm_map_size =
(sizeof(acl_nfs4_perm_map) / sizeof(acl_nfs4_perm_map[0]));

static const acl_perm_map_t acl_nfs4_flag_map[] = {
{ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACL_ENTRY_FILE_INHERIT},
Expand All @@ -98,8 +98,8 @@ static const acl_perm_map_t acl_nfs4_flag_map[] = {
#endif
};

static const int acl_nfs4_flag_map_size =
(int)(sizeof(acl_nfs4_flag_map)/sizeof(acl_nfs4_flag_map[0]));
static const size_t acl_nfs4_flag_map_size =
(sizeof(acl_nfs4_flag_map) / sizeof(acl_nfs4_flag_map[0]));
#endif /* ARCHIVE_ACL_FREEBSD_NFS4 */

static int
Expand All @@ -114,8 +114,10 @@ translate_acl(struct archive_read_disk *a,
acl_tag_t acl_tag;
acl_entry_t acl_entry;
acl_permset_t acl_permset;
int i, entry_acl_type, perm_map_size;
int entry_acl_type;
size_t perm_map_size;
const acl_perm_map_t *perm_map;
size_t i;
int r, s, ae_id, ae_tag, ae_perm;
void *q;
const char *ae_name;
Expand Down Expand Up @@ -332,13 +334,12 @@ set_acl(struct archive *a, int fd, const char *name,
#endif
int ret;
int ae_type, ae_permset, ae_tag, ae_id;
int perm_map_size;
size_t i, perm_map_size;
const acl_perm_map_t *perm_map;
uid_t ae_uid;
gid_t ae_gid;
const char *ae_name;
int entries;
int i;

ret = ARCHIVE_OK;
entries = archive_acl_reset(abstract_acl, ae_requested_type);
Expand Down
22 changes: 12 additions & 10 deletions libarchive/archive_disk_acl_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ static const acl_perm_map_t acl_posix_perm_map[] = {
{ARCHIVE_ENTRY_ACL_READ, ACL_READ},
};

static const int acl_posix_perm_map_size =
(int)(sizeof(acl_posix_perm_map)/sizeof(acl_posix_perm_map[0]));
static const size_t acl_posix_perm_map_size =
(sizeof(acl_posix_perm_map) / sizeof(acl_posix_perm_map[0]));
#endif /* ARCHIVE_ACL_LIBACL */

#if ARCHIVE_ACL_LIBRICHACL
Expand All @@ -87,8 +87,8 @@ static const acl_perm_map_t acl_nfs4_perm_map[] = {
{ARCHIVE_ENTRY_ACL_SYNCHRONIZE, RICHACE_SYNCHRONIZE}
};

static const int acl_nfs4_perm_map_size =
(int)(sizeof(acl_nfs4_perm_map)/sizeof(acl_nfs4_perm_map[0]));
static const size_t acl_nfs4_perm_map_size =
(sizeof(acl_nfs4_perm_map)/sizeof(acl_nfs4_perm_map[0]));

static const acl_perm_map_t acl_nfs4_flag_map[] = {
{ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, RICHACE_FILE_INHERIT_ACE},
Expand All @@ -98,8 +98,8 @@ static const acl_perm_map_t acl_nfs4_flag_map[] = {
{ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, RICHACE_INHERITED_ACE}
};

static const int acl_nfs4_flag_map_size =
(int)(sizeof(acl_nfs4_flag_map)/sizeof(acl_nfs4_flag_map[0]));
static const size_t acl_nfs4_flag_map_size =
(sizeof(acl_nfs4_flag_map) / sizeof(acl_nfs4_flag_map[0]));
#endif /* ARCHIVE_ACL_LIBRICHACL */

#if ARCHIVE_ACL_LIBACL
Expand All @@ -113,8 +113,9 @@ translate_acl(struct archive_read_disk *a,
acl_tag_t acl_tag;
acl_entry_t acl_entry;
acl_permset_t acl_permset;
int i, entry_acl_type;
int entry_acl_type;
int r, s, ae_id, ae_tag, ae_perm;
size_t i;
void *q;
const char *ae_name;

Expand Down Expand Up @@ -219,7 +220,8 @@ translate_richacl(struct archive_read_disk *a, struct archive_entry *entry,
struct richacl *richacl)
{
int ae_id, ae_tag, ae_perm;
int entry_acl_type, i;
int entry_acl_type;
size_t i;
const char *ae_name;

struct richace *richace;
Expand Down Expand Up @@ -326,7 +328,7 @@ set_richacl(struct archive *a, int fd, const char *name,
gid_t ae_gid;
const char *ae_name;
int entries;
int i;
size_t i;
int ret;
int e = 0;
struct richacl *richacl = NULL;
Expand Down Expand Up @@ -469,7 +471,7 @@ set_acl(struct archive *a, int fd, const char *name,
gid_t ae_gid;
const char *ae_name;
int entries;
int i;
size_t i;
int ret;
acl_t acl = NULL;
acl_entry_t acl_entry;
Expand Down
16 changes: 8 additions & 8 deletions libarchive/archive_disk_acl_sunos.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ static const acl_perm_map_t acl_nfs4_perm_map[] = {
{ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACE_SYNCHRONIZE}
};

static const int acl_nfs4_perm_map_size =
(int)(sizeof(acl_nfs4_perm_map)/sizeof(acl_nfs4_perm_map[0]));
static const size_t acl_nfs4_perm_map_size =
(sizeof(acl_nfs4_perm_map)/sizeof(acl_nfs4_perm_map[0]));

static const acl_perm_map_t acl_nfs4_flag_map[] = {
{ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACE_FILE_INHERIT_ACE},
Expand All @@ -96,8 +96,8 @@ static const acl_perm_map_t acl_nfs4_flag_map[] = {
#endif
};

const int acl_nfs4_flag_map_size =
(int)(sizeof(acl_nfs4_flag_map)/sizeof(acl_nfs4_flag_map[0]));
const size_t acl_nfs4_flag_map_size =
(sizeof(acl_nfs4_flag_map) / sizeof(acl_nfs4_flag_map[0]));

#endif /* ARCHIVE_ACL_SUNOS_NFS4 */

Expand Down Expand Up @@ -164,7 +164,7 @@ sun_acl_is_trivial(void *aclp, int aclcnt, mode_t mode, int is_nfs4,
int is_dir, int *trivialp)
{
#if ARCHIVE_ACL_SUNOS_NFS4
int i, p;
size_t i, p;
const uint32_t rperm = ACE_READ_DATA;
const uint32_t wperm = ACE_WRITE_DATA | ACE_APPEND_DATA;
const uint32_t eperm = ACE_EXECUTE;
Expand Down Expand Up @@ -316,10 +316,11 @@ translate_acl(struct archive_read_disk *a,
struct archive_entry *entry, void *aclp, int aclcnt,
int default_entry_acl_type)
{
int e, i;
int e;
int ae_id, ae_tag, ae_perm;
int entry_acl_type;
const char *ae_name;
size_t i;
aclent_t *aclent;
#if ARCHIVE_ACL_SUNOS_NFS4
ace_t *ace;
Expand Down Expand Up @@ -454,13 +455,12 @@ set_acl(struct archive *a, int fd, const char *name,
void *aclp;
int ret;
int ae_type, ae_permset, ae_tag, ae_id;
int perm_map_size;
size_t i, perm_map_size;
const acl_perm_map_t *perm_map;
uid_t ae_uid;
gid_t ae_gid;
const char *ae_name;
int entries;
int i;

ret = ARCHIVE_OK;
entries = archive_acl_reset(abstract_acl, ae_requested_type);
Expand Down
1 change: 0 additions & 1 deletion libarchive/archive_entry_link_resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ archive_entry_linkify(struct archive_entry_linkresolver *res,
default:
break;
}
return;
}

static struct links_entry *
Expand Down
8 changes: 5 additions & 3 deletions libarchive/archive_read_disk_entry_from_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,8 @@ setup_xattrs(struct archive_read_disk *a,
struct archive_entry *entry, int *fd)
{
int namespaces[2];
int i, res;
int res;
unsigned i;

namespaces[0] = EXTATTR_NAMESPACE_USER;
namespaces[1] = EXTATTR_NAMESPACE_SYSTEM;
Expand Down Expand Up @@ -894,7 +895,8 @@ setup_sparse_fiemap(struct archive_read_disk *a,
do_fiemap = 1;
size = archive_entry_size(entry);
for (iters = 0; ; ++iters) {
int i, r;
size_t i;
int r;

r = ioctl(*fd, FS_IOC_FIEMAP, fm);
if (r < 0) {
Expand All @@ -911,7 +913,7 @@ setup_sparse_fiemap(struct archive_read_disk *a,
break;
}
fe = fm->fm_extents;
for (i = 0; i < (int)fm->fm_mapped_extents; i++, fe++) {
for (i = 0; i < fm->fm_mapped_extents; i++, fe++) {
if (!(fe->fe_flags & FIEMAP_EXTENT_UNWRITTEN)) {
/* The fe_length of the last block does not
* adjust itself to its size files. */
Expand Down
2 changes: 1 addition & 1 deletion libarchive/archive_read_open_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ file_skip(struct archive *a, void *client_data, int64_t request)
struct read_fd_data *mine = (struct read_fd_data *)client_data;
int64_t skip = request;
int64_t old_offset, new_offset;
int skip_bits = sizeof(skip) * 8 - 1; /* off_t is a signed type. */

if (!mine->use_lseek)
return (0);

/* Reduce a request that would overflow the 'skip' variable. */
if (sizeof(request) > sizeof(skip)) {
int skip_bits = sizeof(skip) * 8 - 1; /* off_t is a signed type. */
int64_t max_skip =
(((int64_t)1 << (skip_bits - 1)) - 1) * 2 + 1;
if (request > max_skip)
Expand Down
2 changes: 1 addition & 1 deletion libarchive/archive_read_open_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ file_skip(struct archive *a, void *client_data, int64_t request)
#else
long skip = (long)request;
#endif
int skip_bits = sizeof(skip) * 8 - 1;

(void)a; /* UNUSED */

Expand All @@ -145,6 +144,7 @@ file_skip(struct archive *a, void *client_data, int64_t request)

/* If request is too big for a long or an off_t, reduce it. */
if (sizeof(request) > sizeof(skip)) {
int skip_bits = sizeof(skip) * 8 - 1;
int64_t max_skip =
(((int64_t)1 << (skip_bits - 1)) - 1) * 2 + 1;
if (request > max_skip)
Expand Down
2 changes: 1 addition & 1 deletion libarchive/archive_read_support_filter_bzip2.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ bzip2_reader_init(struct archive_read_filter *self)
self->code = ARCHIVE_FILTER_BZIP2;
self->name = "bzip2";

state = (struct private_data *)calloc(sizeof(*state), 1);
state = (struct private_data *)calloc(1, sizeof(*state));
out_block = (unsigned char *)malloc(out_block_size);
if (state == NULL || out_block == NULL) {
archive_set_error(&self->archive->archive, ENOMEM,
Expand Down
2 changes: 1 addition & 1 deletion libarchive/archive_read_support_filter_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ compress_bidder_init(struct archive_read_filter *self)
self->code = ARCHIVE_FILTER_COMPRESS;
self->name = "compress (.Z)";

state = (struct private_data *)calloc(sizeof(*state), 1);
state = (struct private_data *)calloc(1, sizeof(*state));
out_block = malloc(out_block_size);
if (state == NULL || out_block == NULL) {
free(out_block);
Expand Down
2 changes: 1 addition & 1 deletion libarchive/archive_read_support_filter_gzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ gzip_bidder_init(struct archive_read_filter *self)
self->code = ARCHIVE_FILTER_GZIP;
self->name = "gzip";

state = (struct private_data *)calloc(sizeof(*state), 1);
state = (struct private_data *)calloc(1, sizeof(*state));
out_block = (unsigned char *)malloc(out_block_size);
if (state == NULL || out_block == NULL) {
free(out_block);
Expand Down

0 comments on commit 2218fe1

Please sign in to comment.