Index: libarchive-2.4.12/libarchive/archive_entry.c =================================================================== --- libarchive-2.4.12.orig/libarchive/archive_entry.c +++ libarchive-2.4.12/libarchive/archive_entry.c @@ -1635,9 +1635,9 @@ prefix_w(const wchar_t *start, const wch * SUCH DAMAGE. */ -static struct flag { - const char *name; - const wchar_t *wname; +static const struct flag { + const char name[16]; + const wchar_t wname[16]; unsigned long set; unsigned long clear; } flags[] = { @@ -1700,7 +1700,7 @@ static struct flag { #ifdef EXT2_NOATIME_FL /* 'A' */ { "noatime", L"noatime", 0, EXT2_NOATIME_FL}, #endif - { NULL, NULL, 0, 0 } + { "", L"", 0, 0 } }; /* @@ -1714,12 +1714,12 @@ ae_fflagstostr(unsigned long bitset, uns char *string, *dp; const char *sp; unsigned long bits; - struct flag *flag; + const struct flag *flag; size_t length; bits = bitset | bitclear; length = 0; - for (flag = flags; flag->name != NULL; flag++) + for (flag = flags; *(flag->name); flag++) if (bits & (flag->set | flag->clear)) { length += strlen(flag->name) + 1; bits &= ~(flag->set | flag->clear); @@ -1732,7 +1732,7 @@ ae_fflagstostr(unsigned long bitset, uns return (NULL); dp = string; - for (flag = flags; flag->name != NULL; flag++) { + for (flag = flags; *(flag->name); flag++) { if (bitset & flag->set || bitclear & flag->clear) { sp = flag->name + 2; } else if (bitset & flag->clear || bitclear & flag->set) { @@ -1766,7 +1766,7 @@ const wchar_t * ae_wcstofflags(const wchar_t *s, unsigned long *setp, unsigned long *clrp) { const wchar_t *start, *end; - struct flag *flag; + const struct flag *flag; unsigned long set, clear; const wchar_t *failed; @@ -1782,7 +1782,7 @@ ae_wcstofflags(const wchar_t *s, unsigne while (*end != L'\0' && *end != L'\t' && *end != L' ' && *end != L',') end++; - for (flag = flags; flag->wname != NULL; flag++) { + for (flag = flags; *(flag->wname); flag++) { if (wmemcmp(start, flag->wname, end - start) == 0) { /* Matched "noXXXX", so reverse the sense. */ clear |= flag->set; Index: libarchive-2.4.12/libarchive/archive_private.h =================================================================== --- libarchive-2.4.12.orig/libarchive/archive_private.h +++ libarchive-2.4.12/libarchive/archive_private.h @@ -70,7 +70,7 @@ struct archive { * Some public API functions depend on the "real" type of the * archive object. */ - struct archive_vtable *vtable; + const struct archive_vtable *vtable; int archive_format; const char *archive_format_name; Index: libarchive-2.4.12/libarchive/archive_read_support_compression_compress.c =================================================================== --- libarchive-2.4.12.orig/libarchive/archive_read_support_compression_compress.c +++ libarchive-2.4.12/libarchive/archive_read_support_compression_compress.c @@ -373,16 +373,20 @@ next_code(struct archive_read *a, struct { int code, newcode; +#ifdef DEBUG static int debug_buff[1024]; static unsigned debug_index; +#endif code = newcode = getbits(a, state, state->bits); if (code < 0) return (code); +#ifdef DEBUG debug_buff[debug_index++] = code; if (debug_index >= sizeof(debug_buff)/sizeof(debug_buff[0])) debug_index = 0; +#endif /* If it's a reset code, reset the dictionary. */ if ((code == 256) && state->use_reset_code) { Index: libarchive-2.4.12/libarchive/archive_read_support_format_tar.c =================================================================== --- libarchive-2.4.12.orig/libarchive/archive_read_support_format_tar.c +++ libarchive-2.4.12/libarchive/archive_read_support_format_tar.c @@ -2184,23 +2184,40 @@ UTF8_mbrtowc(wchar_t *pwc, const char *s static char * base64_decode(const wchar_t *src, size_t len, size_t *out_len) { - static const unsigned char digits[64] = { - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N', - 'O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b', - 'c','d','e','f','g','h','i','j','k','l','m','n','o','p', - 'q','r','s','t','u','v','w','x','y','z','0','1','2','3', - '4','5','6','7','8','9','+','/' }; - static unsigned char decode_table[128]; + /* The decode_table is generated by the folloing code: + + static const unsigned char digits[64] = { + 'A','B','C','D','E','F','G','H','I','J','K','L','M','N', + 'O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b', + 'c','d','e','f','g','h','i','j','k','l','m','n','o','p', + 'q','r','s','t','u','v','w','x','y','z','0','1','2','3', + '4','5','6','7','8','9','+','/' }; + size_t i; + memset(decode_table, 0xff, sizeof(decode_table)); + for (i = 0; i < sizeof(digits); i++) + decode_table[digits[i]] = i; + */ + + static unsigned char decode_table[128] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, + 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff + }; char *out, *d; - /* If the decode table is not yet initialized, prepare it. */ - if (decode_table[digits[1]] != 1) { - size_t i; - memset(decode_table, 0xff, sizeof(decode_table)); - for (i = 0; i < sizeof(digits); i++) - decode_table[digits[i]] = i; - } - /* Allocate enough space to hold the entire output. */ /* Note that we may not use all of this... */ out = (char *)malloc((len * 3 + 3) / 4); Index: libarchive-2.4.12/libarchive/archive_read_support_format_zip.c =================================================================== --- libarchive-2.4.12.orig/libarchive/archive_read_support_format_zip.c +++ libarchive-2.4.12/libarchive/archive_read_support_format_zip.c @@ -103,7 +103,7 @@ struct zip_file_header { char extra_length[2]; }; -static const char *compression_names[] = { +static const char compression_names[][16] = { "uncompressed", "shrinking", "reduced-1", Index: libarchive-2.4.12/libarchive/archive_write.c =================================================================== --- libarchive-2.4.12.orig/libarchive/archive_write.c +++ libarchive-2.4.12/libarchive/archive_write.c @@ -57,36 +57,25 @@ __FBSDID("$FreeBSD: src/lib/libarchive/a #include "archive_private.h" #include "archive_write_private.h" -static struct archive_vtable *archive_write_vtable(void); - static int _archive_write_close(struct archive *); static int _archive_write_finish(struct archive *); static int _archive_write_header(struct archive *, struct archive_entry *); static int _archive_write_finish_entry(struct archive *); static ssize_t _archive_write_data(struct archive *, const void *, size_t); -static struct archive_vtable * -archive_write_vtable(void) -{ - static struct archive_vtable av; - static int inited = 0; - - if (!inited) { - av.archive_write_close = _archive_write_close; - av.archive_write_finish = _archive_write_finish; - av.archive_write_header = _archive_write_header; - av.archive_write_finish_entry = _archive_write_finish_entry; - av.archive_write_data = _archive_write_data; - } - return (&av); -} - /* * Allocate, initialize and return an archive object. */ struct archive * archive_write_new(void) { + static const struct archive_vtable av = { + .archive_write_close = _archive_write_close, + .archive_write_finish = _archive_write_finish, + .archive_write_header = _archive_write_header, + .archive_write_finish_entry = _archive_write_finish_entry, + .archive_write_data = _archive_write_data + }; struct archive_write *a; unsigned char *nulls; @@ -96,7 +85,7 @@ archive_write_new(void) memset(a, 0, sizeof(*a)); a->archive.magic = ARCHIVE_WRITE_MAGIC; a->archive.state = ARCHIVE_STATE_NEW; - a->archive.vtable = archive_write_vtable(); + a->archive.vtable = &av; a->bytes_per_block = ARCHIVE_DEFAULT_BYTES_PER_BLOCK; a->bytes_in_last_block = -1; /* Default */ Index: libarchive-2.4.12/libarchive/archive_write_disk.c =================================================================== --- libarchive-2.4.12.orig/libarchive/archive_write_disk.c +++ libarchive-2.4.12/libarchive/archive_write_disk.c @@ -226,8 +226,6 @@ static gid_t trivial_lookup_gid(void *, static uid_t trivial_lookup_uid(void *, const char *, uid_t); -static struct archive_vtable *archive_write_disk_vtable(void); - static int _archive_write_close(struct archive *); static int _archive_write_finish(struct archive *); static int _archive_write_header(struct archive *, struct archive_entry *); @@ -235,24 +233,6 @@ static int _archive_write_finish_entry(s static ssize_t _archive_write_data(struct archive *, const void *, size_t); static ssize_t _archive_write_data_block(struct archive *, const void *, size_t, off_t); -static struct archive_vtable * -archive_write_disk_vtable(void) -{ - static struct archive_vtable av; - static int inited = 0; - - if (!inited) { - av.archive_write_close = _archive_write_close; - av.archive_write_finish = _archive_write_finish; - av.archive_write_header = _archive_write_header; - av.archive_write_finish_entry = _archive_write_finish_entry; - av.archive_write_data = _archive_write_data; - av.archive_write_data_block = _archive_write_data_block; - } - return (&av); -} - - int archive_write_disk_set_options(struct archive *_a, int flags) { @@ -624,6 +604,14 @@ archive_write_disk_set_user_lookup(struc struct archive * archive_write_disk_new(void) { + static const struct archive_vtable av = { + .archive_write_close = _archive_write_close, + .archive_write_finish = _archive_write_finish, + .archive_write_header = _archive_write_header, + .archive_write_finish_entry = _archive_write_finish_entry, + .archive_write_data = _archive_write_data, + .archive_write_data_block = _archive_write_data_block + }; struct archive_write_disk *a; a = (struct archive_write_disk *)malloc(sizeof(*a)); @@ -633,7 +621,7 @@ archive_write_disk_new(void) a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC; /* We're ready to write a header immediately. */ a->archive.state = ARCHIVE_STATE_HEADER; - a->archive.vtable = archive_write_disk_vtable(); + a->archive.vtable = &av; a->lookup_uid = trivial_lookup_uid; a->lookup_gid = trivial_lookup_gid; a->user_uid = geteuid(); Index: libarchive-2.4.12/libarchive/archive_write_set_format_by_name.c =================================================================== --- libarchive-2.4.12.orig/libarchive/archive_write_set_format_by_name.c +++ libarchive-2.4.12/libarchive/archive_write_set_format_by_name.c @@ -42,7 +42,7 @@ __FBSDID("$FreeBSD: src/lib/libarchive/a /* A table that maps names to functions. */ static -struct { const char *name; int (*setter)(struct archive *); } names[] = +const struct { const char name[12]; int (*setter)(struct archive *); } names[] = { { "arbsd", archive_write_set_format_ar_bsd }, { "ar", archive_write_set_format_ar_bsd }, @@ -56,7 +56,7 @@ struct { const char *name; int (*setter) { "shar", archive_write_set_format_shar }, { "shardump", archive_write_set_format_shar_dump }, { "ustar", archive_write_set_format_ustar }, - { NULL, NULL } + { "", NULL } }; int @@ -64,7 +64,7 @@ archive_write_set_format_by_name(struct { int i; - for (i = 0; names[i].name != NULL; i++) { + for (i = 0; names[i].setter != NULL; i++) { if (strcmp(name, names[i].name) == 0) return ((names[i].setter)(a)); } Index: libarchive-2.4.12/libarchive/archive_write_set_format.c =================================================================== --- libarchive-2.4.12.orig/libarchive/archive_write_set_format.c +++ libarchive-2.4.12/libarchive/archive_write_set_format.c @@ -39,7 +39,7 @@ __FBSDID("$FreeBSD: src/lib/libarchive/a /* A table that maps format codes to functions. */ static -struct { int code; int (*setter)(struct archive *); } codes[] = +const struct { int code; int (*setter)(struct archive *); } codes[] = { { ARCHIVE_FORMAT_CPIO, archive_write_set_format_cpio }, { ARCHIVE_FORMAT_CPIO_SVR4_NOCRC, archive_write_set_format_cpio_newc },