Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a handful of compiler warnings #1862

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AtariDreams
Copy link
Contributor

@AtariDreams AtariDreams commented Apr 20, 2023

This fixes a couple of warnings raised by clang.

@AtariDreams
Copy link
Contributor Author

Any updates on this?

@kientzle
Copy link
Contributor

kientzle commented Jul 9, 2023

You say this fixes compiler warnings? What compilers have you tried, and what were the warnings you saw?

@evelikov
Copy link
Contributor

Not a maintainer here, so take this with a pinch of salt:

On most, if not all platforms sizeof returns a size_t, although not many compilers will warn if the value is saved as an int. Having the commit message say, "Happens with compiler X, version Y and warning -Wfoobar" would be great.

That said, the commit does a bunch of unrelated changes at once. It would be better if they are split:

  • int -> size_t for sizeof
  • convert while loop into a for loop
  • drop some empty/white lines
  • dropping no-op returns
  • swap calloc argument order
  • removing duplicate includes - unistd.h , errno.h
  • drop misc changes that already landed with Prefer OR over addition #1915

The loop & whitespace ones seem superfluous, the rest are good fixes.

HTH

@evelikov
Copy link
Contributor

@AtariDreams please update the PR to address the earlier review suggestions.

@AtariDreams
Copy link
Contributor Author

@evelikov Done!

examples/minitar/minitar.c Outdated Show resolved Hide resolved
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return removal is good but should be part of the "remove redundant" PR.

libarchive/archive_disk_acl_darwin.c Show resolved Hide resolved
libarchive/archive_disk_acl_freebsd.c Show resolved Hide resolved
libarchive/archive_disk_acl_linux.c Show resolved Hide resolved
libarchive/archive_read_support_filter_lzop.c Show resolved Hide resolved
libarchive/archive_read_support_format_rar.c Outdated Show resolved Hide resolved
libarchive/archive_read_support_format_rar.c Show resolved Hide resolved
This fixes a couple of warnings raised by clang.
@evelikov
Copy link
Contributor

@AtariDreams I think the maintainers are looking for an answer to their earlier questions:

You say this fixes compiler warnings? What compilers have you tried, and what were the warnings you saw?

Personally it makes sense to also add the relevant -Wfoobar options to the autotools and cmake builds as part of this PR. This way it a) clearly illustrates/answers the above questions and b) reduces the odds of reintroducing similar changes in the future.

HTH o/

Copy link
Contributor

@kientzle kientzle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some good changes here and some that seem to have no reason.

I also still want to know what the warnings were. I tried compiling the current libarchive code with a recent clang with -Wall and I don't see the warnings you're talking about.

@@ -1090,7 +1090,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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the argument from this ENDMACRO() but no other? Was this one wrong somehow?

@@ -133,13 +133,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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip here should be off_t since that's the type that the lseek calls expect.

@@ -195,7 +195,7 @@ 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++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix!

@@ -793,7 +793,8 @@ setup_xattrs(struct archive_read_disk *a,
struct archive_entry *entry, int *fd)
{
int namespaces[2];
int i, res;
int res;
unsigned i;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsigned here is not necessary.

libarchive/archive_read_support_format_rar.c Show resolved Hide resolved
@@ -706,7 +706,7 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry)
const void *attr_value;
size_t attr_size;
int i = archive_entry_xattr_reset(a->entry);
while (i--) {
while (i-- > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good change that fixes a real warning on some compilers.

@@ -4574,11 +4574,11 @@ set_xattrs(struct archive_write_disk *a)
struct archive_string errlist;
int ret = ARCHIVE_OK;
int i = archive_entry_xattr_reset(entry);
short fail = 0;
int fail = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int is a better choice here.

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]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unnecessary style change: I generally prefer to use int unless there's a need to do otherwise. In this case, the map is a fixed list (just above) that has less than 20 entries. So int works perfectly fine and reduces the need for extra casting below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants