Skip to content

Commit

Permalink
Use cleanup_fdp to quiet clang-analyzer
Browse files Browse the repository at this point in the history
This avoids a "dead nested assignment" warning because clang
doesn't understand that we're explicitly setting to -1 for the
cleanup function.

Signed-off-by: Colin Walters <walters@verbum.org>
  • Loading branch information
cgwalters committed Aug 29, 2023
1 parent 597a766 commit 6da0b95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 4 additions & 0 deletions libcomposefs/lcfs-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ static inline void cleanup_freep(void *p)
free(*pp);
}

// A wrapper around close() that takes a pointer to a file descriptor (integer):
// - Never returns an error (and preserves errno)
// - Sets the value to -1 after closing to make cleanup idempotent
static inline void cleanup_fdp(int *fdp)
{
PROTECT_ERRNO;
Expand All @@ -55,6 +58,7 @@ static inline void cleanup_fdp(int *fdp)
fd = *fdp;
if (fd != -1)
(void)close(fd);
*fdp = -1;
}

#define cleanup_free __attribute__((cleanup(cleanup_freep)))
Expand Down
6 changes: 2 additions & 4 deletions tools/mkcomposefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ static int copy_file_with_dirs_if_needed(const char *src, const char *dst_base,
return res;
}
}
close(sfd);
sfd = -1;
cleanup_fdp(&sfd);

/* Make sure file is readable by all */
res = fchmod(dfd, 0644);
Expand All @@ -258,8 +257,7 @@ static int copy_file_with_dirs_if_needed(const char *src, const char *dst_base,
if (res < 0) {
return res;
}
close(dfd);
dfd = -1;
cleanup_fdp(&dfd);

if (try_enable_fsverity) {
/* Try to enable fsverity */
Expand Down

0 comments on commit 6da0b95

Please sign in to comment.