Skip to content

Commit

Permalink
Make single bit bitfields unsigned to avoid clang 16 warning (libarch…
Browse files Browse the repository at this point in the history
…ive#1860)

Clang 16 introduced a warning about single bit bitfields in structs,
which is triggered by a few libarchive formats:

libarchive/archive_write_set_format_7zip.c:1541:13: error: implicit
truncation from 'int' to a one-bit wide bit-field changes value from 1
to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
                    file->dir = 1;
                              ^ ~

This is because single bit bitfields only support values -1 and 0, if
they are signed.

For bitfields with two or more bits this can be intentional, but single
bit bitfields are typically used as booleans, so it is better to make
them unsigned.

(cherry picked from commit f180dca)
  • Loading branch information
DimitryAndric authored and jcfr committed Dec 13, 2024
1 parent 6c33011 commit 14ec55f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion libarchive/archive_write_set_format_7zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ struct file {
mode_t mode;
uint32_t crc32;

signed int dir:1;
unsigned dir:1;
};

struct _7zip {
Expand Down
14 changes: 7 additions & 7 deletions libarchive/archive_write_set_format_iso9660.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ struct isoent {
struct extr_rec *current;
} extr_rec_list;

signed int virtual:1;
unsigned int virtual:1;
/* If set to one, this file type is a directory.
* A convenience flag to be used as
* "archive_entry_filetype(isoent->file->entry) == AE_IFDIR".
*/
signed int dir:1;
unsigned int dir:1;
};

struct hardlink {
Expand Down Expand Up @@ -755,9 +755,9 @@ struct iso9660 {

/* Used for making zisofs. */
struct {
signed int detect_magic:1;
signed int making:1;
signed int allzero:1;
unsigned int detect_magic:1;
unsigned int making:1;
unsigned int allzero:1;
unsigned char magic_buffer[64];
int magic_cnt;

Expand Down Expand Up @@ -7802,8 +7802,8 @@ struct zisofs_extract {
uint64_t pz_uncompressed_size;
size_t uncompressed_buffer_size;

signed int initialized:1;
signed int header_passed:1;
unsigned int initialized:1;
unsigned int header_passed:1;

uint32_t pz_offset;
unsigned char *block_pointers;
Expand Down
4 changes: 2 additions & 2 deletions libarchive/archive_write_set_format_xar.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ struct file {
struct heap_data data;
struct archive_string script;

signed int virtual:1;
signed int dir:1;
unsigned int virtual:1;
unsigned int dir:1;
};

struct hardlink {
Expand Down

0 comments on commit 14ec55f

Please sign in to comment.