]> wimlib.net Git - wimlib/commitdiff
Replace BUILD_BUG_ON() with STATIC_ASSERT()
authorEric Biggers <ebiggers3@gmail.com>
Sun, 13 Sep 2015 16:36:22 +0000 (11:36 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 19 Sep 2015 16:36:28 +0000 (11:36 -0500)
19 files changed:
include/wimlib/bitops.h
include/wimlib/compiler.h
include/wimlib/decompress_common.h
include/wimlib/lzms_common.h
include/wimlib/reparse.h
include/wimlib/wof.h
src/blob_table.c
src/capture_common.c
src/decompress_common.c
src/dentry.c
src/header.c
src/lzms_compress.c
src/lzms_decompress.c
src/lzx_compress.c
src/lzx_decompress.c
src/update_image.c
src/wimboot.c
src/win32_apply.c
src/write.c

index 2e7a948fd9b91bb9d4065a49a23252ff77d1dc90..191e95a10f7d537eb215cddfa90914adbe94f334 100644 (file)
@@ -44,7 +44,7 @@ fls64(u64 v)
 static inline unsigned
 flsw(machine_word_t v)
 {
 static inline unsigned
 flsw(machine_word_t v)
 {
-       BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
+       STATIC_ASSERT(WORDSIZE == 4 || WORDSIZE == 8);
        if (WORDSIZE == 4)
                return fls32(v);
        else
        if (WORDSIZE == 4)
                return fls32(v);
        else
@@ -82,7 +82,7 @@ ffs64(u64 v)
 static inline unsigned
 ffsw(machine_word_t v)
 {
 static inline unsigned
 ffsw(machine_word_t v)
 {
-       BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
+       STATIC_ASSERT(WORDSIZE == 4 || WORDSIZE == 8);
        if (WORDSIZE == 4)
                return ffs32(v);
        else
        if (WORDSIZE == 4)
                return ffs32(v);
        else
index 5327318832f3c7ffb6dd9484117e73f9333a9f75..72c100a286fd9315cccebe5c76921c1faa815f6d 100644 (file)
 #  define _force_attr
 #endif
 
 #  define _force_attr
 #endif
 
-#ifndef BUILD_BUG_ON
-#  define BUILD_BUG_ON(expr)   ((void)sizeof(char[1 - 2*!!(expr)]))
+/* STATIC_ASSERT() - verify the truth of an expression at compilation time.  */
+#if __STDC_VERSION__ >= 201112L
+#  define STATIC_ASSERT(expr)  _Static_assert((expr), "")
+#else
+#  define STATIC_ASSERT(expr)  ((void)sizeof(char[1 - 2 * !(expr)]))
 #endif
 
 #endif /* _WIMLIB_COMPILER_H */
 #endif
 
 #endif /* _WIMLIB_COMPILER_H */
index 70f7dd5a8f4ed508b636ce028105e018f0c81801..5d7c4e5abb441ce5e3fe625869c673d1a4b4b234 100644 (file)
@@ -261,7 +261,7 @@ repeat_byte(u8 b)
 {
        machine_word_t v;
 
 {
        machine_word_t v;
 
-       BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
+       STATIC_ASSERT(WORDSIZE == 4 || WORDSIZE == 8);
 
        v = b;
        v |= v << 8;
 
        v = b;
        v |= v << 8;
index 093e50d2d0de1c073b926cf0a0001c6588088c50..56e351109546a0db14e821203de58758b6b0c16e 100644 (file)
@@ -74,7 +74,7 @@ lzms_init_probabilities(struct lzms_probabilites *probs);
 static inline void
 lzms_update_probability_entry(struct lzms_probability_entry *entry, int bit)
 {
 static inline void
 lzms_update_probability_entry(struct lzms_probability_entry *entry, int bit)
 {
-       BUILD_BUG_ON(LZMS_PROBABILITY_DENOMINATOR != sizeof(entry->recent_bits) * 8);
+       STATIC_ASSERT(LZMS_PROBABILITY_DENOMINATOR == sizeof(entry->recent_bits) * 8);
 
 #ifdef __x86_64__
        if (__builtin_constant_p(bit)) {
 
 #ifdef __x86_64__
        if (__builtin_constant_p(bit)) {
index 235c1680c17bca3a5bbd68e386864f05bd3d6f53..7627ad41cca4ce7aff1db00f9781aebade2ca75f 100644 (file)
@@ -52,10 +52,10 @@ struct reparse_buffer_disk {
 static inline void
 check_reparse_buffer_disk(void)
 {
 static inline void
 check_reparse_buffer_disk(void)
 {
-       BUILD_BUG_ON(offsetof(struct reparse_buffer_disk, rpdata) != 8);
-       BUILD_BUG_ON(offsetof(struct reparse_buffer_disk, link.junction.data) != 16);
-       BUILD_BUG_ON(offsetof(struct reparse_buffer_disk, link.symlink.data) != 20);
-       BUILD_BUG_ON(sizeof(struct reparse_buffer_disk) != REPARSE_POINT_MAX_SIZE);
+       STATIC_ASSERT(offsetof(struct reparse_buffer_disk, rpdata) == 8);
+       STATIC_ASSERT(offsetof(struct reparse_buffer_disk, link.junction.data) == 16);
+       STATIC_ASSERT(offsetof(struct reparse_buffer_disk, link.symlink.data) == 20);
+       STATIC_ASSERT(sizeof(struct reparse_buffer_disk) == REPARSE_POINT_MAX_SIZE);
 }
 
 /* Wrapper around a symbolic link or junction reparse point
 }
 
 /* Wrapper around a symbolic link or junction reparse point
index 71d97d80674a716c1b4694ea31a11ace199122f5..85ba31b72b06dc17cb0a88591aa9aaa1a7544312 100644 (file)
@@ -294,9 +294,9 @@ struct WimOverlay_dat_entry_2 {
 static inline void
 wof_check_structs(void)
 {
 static inline void
 wof_check_structs(void)
 {
-       BUILD_BUG_ON(sizeof(struct WimOverlay_dat_header) != 24);
-       BUILD_BUG_ON(sizeof(struct WimOverlay_dat_entry_1) != 40);
-       BUILD_BUG_ON(sizeof(struct WimOverlay_dat_entry_2) != 104);
+       STATIC_ASSERT(sizeof(struct WimOverlay_dat_header) == 24);
+       STATIC_ASSERT(sizeof(struct WimOverlay_dat_entry_1) == 40);
+       STATIC_ASSERT(sizeof(struct WimOverlay_dat_entry_2) == 104);
 }
 
 /*****************************************************************************
 }
 
 /*****************************************************************************
index 43ea4854b949bb7be932ca71ed36df4392f98dff..dd5bbd7e7e14c41877becc1afaaaac627a2573f0 100644 (file)
@@ -110,7 +110,7 @@ free_blob_table(struct blob_table *table)
 struct blob_descriptor *
 new_blob_descriptor(void)
 {
 struct blob_descriptor *
 new_blob_descriptor(void)
 {
-       BUILD_BUG_ON(BLOB_NONEXISTENT != 0);
+       STATIC_ASSERT(BLOB_NONEXISTENT == 0);
        return CALLOC(1, sizeof(struct blob_descriptor));
 }
 
        return CALLOC(1, sizeof(struct blob_descriptor));
 }
 
@@ -135,8 +135,8 @@ clone_blob_descriptor(const struct blob_descriptor *old)
 #endif
 #ifdef WITH_FUSE
        case BLOB_IN_STAGING_FILE:
 #endif
 #ifdef WITH_FUSE
        case BLOB_IN_STAGING_FILE:
-               BUILD_BUG_ON((void*)&old->file_on_disk !=
-                            (void*)&old->staging_file_name);
+               STATIC_ASSERT((void*)&old->file_on_disk ==
+                             (void*)&old->staging_file_name);
 #endif
                new->file_on_disk = TSTRDUP(old->file_on_disk);
                if (new->file_on_disk == NULL)
 #endif
                new->file_on_disk = TSTRDUP(old->file_on_disk);
                if (new->file_on_disk == NULL)
@@ -178,12 +178,12 @@ blob_release_location(struct blob_descriptor *blob)
 #endif
 #ifdef WITH_FUSE
        case BLOB_IN_STAGING_FILE:
 #endif
 #ifdef WITH_FUSE
        case BLOB_IN_STAGING_FILE:
-               BUILD_BUG_ON((void*)&blob->file_on_disk !=
-                            (void*)&blob->staging_file_name);
+               STATIC_ASSERT((void*)&blob->file_on_disk ==
+                             (void*)&blob->staging_file_name);
 #endif
        case BLOB_IN_ATTACHED_BUFFER:
 #endif
        case BLOB_IN_ATTACHED_BUFFER:
-               BUILD_BUG_ON((void*)&blob->file_on_disk !=
-                            (void*)&blob->attached_buffer);
+               STATIC_ASSERT((void*)&blob->file_on_disk ==
+                             (void*)&blob->attached_buffer);
                FREE(blob->file_on_disk);
                break;
 #ifdef WITH_NTFS_3G
                FREE(blob->file_on_disk);
                break;
 #ifdef WITH_NTFS_3G
@@ -638,10 +638,10 @@ do_load_solid_info(WIMStruct *wim, struct wim_resource_descriptor **rdescs,
 
                /* Compression format numbers must be the same as in
                 * WIMGAPI to be compatible here.  */
 
                /* Compression format numbers must be the same as in
                 * WIMGAPI to be compatible here.  */
-               BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_NONE != 0);
-               BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_XPRESS != 1);
-               BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_LZX != 2);
-               BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_LZMS != 3);
+               STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_NONE == 0);
+               STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_XPRESS == 1);
+               STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_LZX == 2);
+               STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_LZMS == 3);
                rdesc->compression_type = le32_to_cpu(hdr.compression_format);
                rdesc->chunk_size = le32_to_cpu(hdr.chunk_size);
        }
                rdesc->compression_type = le32_to_cpu(hdr.compression_format);
                rdesc->chunk_size = le32_to_cpu(hdr.chunk_size);
        }
index 353ff2b67f64fabb134eae8150175a6f54ec27e8..0a2f26cd816aeca992d8404984b68d4083dbfbc6 100644 (file)
@@ -135,7 +135,7 @@ mangle_pat(tchar *pat, const tchar *path, unsigned long line_no)
         * Note: we expect that this function produces patterns that can be used
         * for both filesystem paths and WIM paths, so the desired path
         * separators must be the same.  */
         * Note: we expect that this function produces patterns that can be used
         * for both filesystem paths and WIM paths, so the desired path
         * separators must be the same.  */
-       BUILD_BUG_ON(OS_PREFERRED_PATH_SEPARATOR != WIM_PATH_SEPARATOR);
+       STATIC_ASSERT(OS_PREFERRED_PATH_SEPARATOR == WIM_PATH_SEPARATOR);
        do_canonicalize_path(pat, pat);
 
        /* Relative patterns can only match file names, so they must be
        do_canonicalize_path(pat, pat);
 
        /* Relative patterns can only match file names, so they must be
index c2f76955c17043f2b39dcab98d9fdb7a59e36f7b..a490882d8542cd230877f6405ff34988ba98b322 100644 (file)
@@ -281,7 +281,7 @@ make_huffman_decode_table(u16 decode_table[const],
                        aliased_word_t *p;
                        unsigned n;
 
                        aliased_word_t *p;
                        unsigned n;
 
-                       BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
+                       STATIC_ASSERT(WORDSIZE == 4 || WORDSIZE == 8);
 
                        v = MAKE_DIRECT_ENTRY(sorted_syms[sym_idx], codeword_len);
                        v |= v << 16;
 
                        v = MAKE_DIRECT_ENTRY(sorted_syms[sym_idx], codeword_len);
                        v |= v << 16;
index 4f842eaa6a413d3588be38f1a58f85ef2600429c..13940a32d3b96c2a4c7d6f9a60babea8e3931ceb 100644 (file)
@@ -1394,7 +1394,7 @@ read_dentry(const u8 * restrict buf, size_t buf_len,
        u64 calculated_size;
        int ret;
 
        u64 calculated_size;
        int ret;
 
-       BUILD_BUG_ON(sizeof(struct wim_dentry_on_disk) != WIM_DENTRY_DISK_SIZE);
+       STATIC_ASSERT(sizeof(struct wim_dentry_on_disk) == WIM_DENTRY_DISK_SIZE);
 
        /* Before reading the whole dentry, we need to read just the length.
         * This is because a dentry of length 8 (that is, just the length field)
 
        /* Before reading the whole dentry, we need to read just the length.
         * This is because a dentry of length 8 (that is, just the length field)
index d5449507974292560824f3ff8c829e5ae8fdf07c..cf19396317ca3af6da227c6b4b60d1bd180b4b06 100644 (file)
@@ -76,7 +76,7 @@ read_wim_header(WIMStruct *wim, struct wim_header *hdr)
                filename = pipe_str;
        }
 
                filename = pipe_str;
        }
 
-       BUILD_BUG_ON(sizeof(struct wim_header_disk) != WIM_HEADER_DISK_SIZE);
+       STATIC_ASSERT(sizeof(struct wim_header_disk) == WIM_HEADER_DISK_SIZE);
 
        ret = full_read(in_fd, &disk_hdr, sizeof(disk_hdr));
        if (ret)
 
        ret = full_read(in_fd, &disk_hdr, sizeof(disk_hdr));
        if (ret)
index f438e91cd15156f48e8371f3bf5f1cc6aa044413..099a9dbf3c8ac1c8fb629b561b0e2de2450c3287 100644 (file)
@@ -173,7 +173,7 @@ struct lzms_item {
 static inline void
 check_that_powers_fit_in_bitfield(void)
 {
 static inline void
 check_that_powers_fit_in_bitfield(void)
 {
-       BUILD_BUG_ON(LZMS_NUM_DELTA_POWER_SYMS > (1 << (31 - DELTA_SOURCE_POWER_SHIFT)));
+       STATIC_ASSERT(LZMS_NUM_DELTA_POWER_SYMS <= (1 << (31 - DELTA_SOURCE_POWER_SHIFT)));
 }
 
 /* A stripped-down version of the adaptive state in LZMS which excludes the
 }
 
 /* A stripped-down version of the adaptive state in LZMS which excludes the
@@ -975,7 +975,7 @@ static inline void
 check_cost_shift(void)
 {
        /* lzms_bit_costs is hard-coded to the current COST_SHIFT.  */
 check_cost_shift(void)
 {
        /* lzms_bit_costs is hard-coded to the current COST_SHIFT.  */
-       BUILD_BUG_ON(COST_SHIFT != 6);
+       STATIC_ASSERT(COST_SHIFT == 6);
 }
 
 #if 0
 }
 
 #if 0
@@ -1180,7 +1180,7 @@ static void
 lzms_init_delta_matchfinder(struct lzms_compressor *c)
 {
        /* Set all entries to use an invalid power, which will never match.  */
 lzms_init_delta_matchfinder(struct lzms_compressor *c)
 {
        /* Set all entries to use an invalid power, which will never match.  */
-       BUILD_BUG_ON(NUM_POWERS_TO_CONSIDER >= (1 << (32 - DELTA_SOURCE_POWER_SHIFT)));
+       STATIC_ASSERT(NUM_POWERS_TO_CONSIDER < (1 << (32 - DELTA_SOURCE_POWER_SHIFT)));
        memset(c->delta_hash_table, 0xFF, sizeof(c->delta_hash_table));
 
        /* Initialize the next hash code for each power.  We can just use zeroes
        memset(c->delta_hash_table, 0xFF, sizeof(c->delta_hash_table));
 
        /* Initialize the next hash code for each power.  We can just use zeroes
@@ -1203,7 +1203,7 @@ lzms_delta_hash(const u8 *p, const u32 pos, u32 span)
         * include in the hash code computation the span and the low-order bits
         * of the current position.  */
 
         * include in the hash code computation the span and the low-order bits
         * of the current position.  */
 
-       BUILD_BUG_ON(NBYTES_HASHED_FOR_DELTA != 3);
+       STATIC_ASSERT(NBYTES_HASHED_FOR_DELTA == 3);
        u8 d0 = *(p + 0) - *(p + 0 - span);
        u8 d1 = *(p + 1) - *(p + 1 - span);
        u8 d2 = *(p + 2) - *(p + 2 - span);
        u8 d0 = *(p + 0) - *(p + 0 - span);
        u8 d1 = *(p + 1) - *(p + 1 - span);
        u8 d2 = *(p + 2) - *(p + 2 - span);
@@ -1712,7 +1712,7 @@ begin:
                        const u32 pos = in_next - c->in_buffer;
 
                        /* Consider each possible power (log2 of span)  */
                        const u32 pos = in_next - c->in_buffer;
 
                        /* Consider each possible power (log2 of span)  */
-                       BUILD_BUG_ON(NUM_POWERS_TO_CONSIDER > LZMS_NUM_DELTA_POWER_SYMS);
+                       STATIC_ASSERT(NUM_POWERS_TO_CONSIDER <= LZMS_NUM_DELTA_POWER_SYMS);
                        for (u32 power = 0; power < NUM_POWERS_TO_CONSIDER; power++) {
 
                                const u32 span = (u32)1 << power;
                        for (u32 power = 0; power < NUM_POWERS_TO_CONSIDER; power++) {
 
                                const u32 span = (u32)1 << power;
@@ -1741,7 +1741,7 @@ begin:
 
                                /* Check the first 3 bytes before entering the
                                 * extension loop.  */
 
                                /* Check the first 3 bytes before entering the
                                 * extension loop.  */
-                               BUILD_BUG_ON(NBYTES_HASHED_FOR_DELTA != 3);
+                               STATIC_ASSERT(NBYTES_HASHED_FOR_DELTA == 3);
                                if (((u8)(*(in_next + 0) - *(in_next + 0 - span)) !=
                                     (u8)(*(matchptr + 0) - *(matchptr + 0 - span))) ||
                                    ((u8)(*(in_next + 1) - *(in_next + 1 - span)) !=
                                if (((u8)(*(in_next + 0) - *(in_next + 0 - span)) !=
                                     (u8)(*(matchptr + 0) - *(matchptr + 0 - span))) ||
                                    ((u8)(*(in_next + 1) - *(in_next + 1 - span)) !=
index 5093a3d32ed2e21322b1eba0f172eec0a8163659..345b51dbf38c6317b6d17b429e3325b36167a1ce 100644 (file)
@@ -796,7 +796,7 @@ lzms_decompress(const void * const restrict in, const size_t in_nbytes,
                                if (pending_lz_offset != 0 &&
                                    out_next != lz_offset_still_pending)
                                {
                                if (pending_lz_offset != 0 &&
                                    out_next != lz_offset_still_pending)
                                {
-                                       BUILD_BUG_ON(LZMS_NUM_LZ_REPS != 3);
+                                       STATIC_ASSERT(LZMS_NUM_LZ_REPS == 3);
                                        recent_lz_offsets[3] = recent_lz_offsets[2];
                                        recent_lz_offsets[2] = recent_lz_offsets[1];
                                        recent_lz_offsets[1] = recent_lz_offsets[0];
                                        recent_lz_offsets[3] = recent_lz_offsets[2];
                                        recent_lz_offsets[2] = recent_lz_offsets[1];
                                        recent_lz_offsets[1] = recent_lz_offsets[0];
@@ -804,7 +804,7 @@ lzms_decompress(const void * const restrict in, const size_t in_nbytes,
                                        pending_lz_offset = 0;
                                }
 
                                        pending_lz_offset = 0;
                                }
 
-                               BUILD_BUG_ON(LZMS_NUM_LZ_REPS != 3);
+                               STATIC_ASSERT(LZMS_NUM_LZ_REPS == 3);
                                if (!lzms_decode_bit(&rd, &lz_rep_states[0],
                                                     LZMS_NUM_LZ_REP_PROBS,
                                                     d->probs.lz_rep[0]))
                                if (!lzms_decode_bit(&rd, &lz_rep_states[0],
                                                     LZMS_NUM_LZ_REP_PROBS,
                                                     d->probs.lz_rep[0]))
@@ -827,7 +827,7 @@ lzms_decompress(const void * const restrict in, const size_t in_nbytes,
                        }
 
                        if (pending_lz_offset != 0) {
                        }
 
                        if (pending_lz_offset != 0) {
-                               BUILD_BUG_ON(LZMS_NUM_LZ_REPS != 3);
+                               STATIC_ASSERT(LZMS_NUM_LZ_REPS == 3);
                                recent_lz_offsets[3] = recent_lz_offsets[2];
                                recent_lz_offsets[2] = recent_lz_offsets[1];
                                recent_lz_offsets[1] = recent_lz_offsets[0];
                                recent_lz_offsets[3] = recent_lz_offsets[2];
                                recent_lz_offsets[2] = recent_lz_offsets[1];
                                recent_lz_offsets[1] = recent_lz_offsets[0];
@@ -872,7 +872,7 @@ lzms_decompress(const void * const restrict in, const size_t in_nbytes,
                                if (pending_delta_pair != 0 &&
                                    out_next != delta_pair_still_pending)
                                {
                                if (pending_delta_pair != 0 &&
                                    out_next != delta_pair_still_pending)
                                {
-                                       BUILD_BUG_ON(LZMS_NUM_DELTA_REPS != 3);
+                                       STATIC_ASSERT(LZMS_NUM_DELTA_REPS == 3);
                                        recent_delta_pairs[3] = recent_delta_pairs[2];
                                        recent_delta_pairs[2] = recent_delta_pairs[1];
                                        recent_delta_pairs[1] = recent_delta_pairs[0];
                                        recent_delta_pairs[3] = recent_delta_pairs[2];
                                        recent_delta_pairs[2] = recent_delta_pairs[1];
                                        recent_delta_pairs[1] = recent_delta_pairs[0];
@@ -880,7 +880,7 @@ lzms_decompress(const void * const restrict in, const size_t in_nbytes,
                                        pending_delta_pair = 0;
                                }
 
                                        pending_delta_pair = 0;
                                }
 
-                               BUILD_BUG_ON(LZMS_NUM_DELTA_REPS != 3);
+                               STATIC_ASSERT(LZMS_NUM_DELTA_REPS == 3);
                                if (!lzms_decode_bit(&rd, &delta_rep_states[0],
                                                     LZMS_NUM_DELTA_REP_PROBS,
                                                     d->probs.delta_rep[0]))
                                if (!lzms_decode_bit(&rd, &delta_rep_states[0],
                                                     LZMS_NUM_DELTA_REP_PROBS,
                                                     d->probs.delta_rep[0]))
@@ -905,7 +905,7 @@ lzms_decompress(const void * const restrict in, const size_t in_nbytes,
                        }
 
                        if (pending_delta_pair != 0) {
                        }
 
                        if (pending_delta_pair != 0) {
-                               BUILD_BUG_ON(LZMS_NUM_DELTA_REPS != 3);
+                               STATIC_ASSERT(LZMS_NUM_DELTA_REPS == 3);
                                recent_delta_pairs[3] = recent_delta_pairs[2];
                                recent_delta_pairs[2] = recent_delta_pairs[1];
                                recent_delta_pairs[1] = recent_delta_pairs[0];
                                recent_delta_pairs[3] = recent_delta_pairs[2];
                                recent_delta_pairs[2] = recent_delta_pairs[1];
                                recent_delta_pairs[1] = recent_delta_pairs[0];
index 3f3b836c636f8dd2bbdac17ae6a7b2d97bb673e0..339f27feb53e2cb894eba462e399da9f9fb9b2e6 100644 (file)
@@ -1121,8 +1121,8 @@ lzx_declare_explicit_offset_match(struct lzx_compressor *c, unsigned len, u32 of
                extra_bits = (offset + LZX_OFFSET_ADJUSTMENT) -
                             lzx_offset_slot_base[offset_slot];
 
                extra_bits = (offset + LZX_OFFSET_ADJUSTMENT) -
                             lzx_offset_slot_base[offset_slot];
 
-               BUILD_BUG_ON(LZX_MAINCODE_MAX_NUM_SYMBOLS > (1 << 10));
-               BUILD_BUG_ON(LZX_LENCODE_NUM_SYMBOLS > (1 << 8));
+               STATIC_ASSERT(LZX_MAINCODE_MAX_NUM_SYMBOLS <= (1 << 10));
+               STATIC_ASSERT(LZX_LENCODE_NUM_SYMBOLS <= (1 << 8));
                *(*next_chosen_item)++ = (struct lzx_item) {
                        .data = (u64)main_symbol |
                                ((u64)len_symbol << 10) |
                *(*next_chosen_item)++ = (struct lzx_item) {
                        .data = (u64)main_symbol |
                                ((u64)len_symbol << 10) |
@@ -1242,7 +1242,7 @@ lzx_find_min_cost_path(struct lzx_compressor * const restrict c,
         * it is no longer needed.  */
        struct lzx_lru_queue queues[512];
 
         * it is no longer needed.  */
        struct lzx_lru_queue queues[512];
 
-       BUILD_BUG_ON(ARRAY_LEN(queues) < LZX_MAX_MATCH_LEN + 1);
+       STATIC_ASSERT(ARRAY_LEN(queues) >= LZX_MAX_MATCH_LEN + 1);
 #define QUEUE(in) (queues[(uintptr_t)(in) % ARRAY_LEN(queues)])
 
        /* Initially, the cost to reach each node is "infinity".  */
 #define QUEUE(in) (queues[(uintptr_t)(in) % ARRAY_LEN(queues)])
 
        /* Initially, the cost to reach each node is "infinity".  */
@@ -1294,7 +1294,7 @@ lzx_find_min_cost_path(struct lzx_compressor * const restrict c,
                        matchptr = in_next - lzx_lru_queue_R0(QUEUE(in_next));
                        if (load_u16_unaligned(matchptr) != load_u16_unaligned(in_next))
                                goto R0_done;
                        matchptr = in_next - lzx_lru_queue_R0(QUEUE(in_next));
                        if (load_u16_unaligned(matchptr) != load_u16_unaligned(in_next))
                                goto R0_done;
-                       BUILD_BUG_ON(LZX_MIN_MATCH_LEN != 2);
+                       STATIC_ASSERT(LZX_MIN_MATCH_LEN == 2);
                        do {
                                u32 cost = cur_node->cost +
                                           c->costs.match_cost[0][
                        do {
                                u32 cost = cur_node->cost +
                                           c->costs.match_cost[0][
@@ -1479,7 +1479,7 @@ lzx_set_default_costs(struct lzx_compressor *c, const u8 *block, u32 block_size)
        unsigned num_used_bytes;
 
        /* The costs below are hard coded to use a scaling factor of 16.  */
        unsigned num_used_bytes;
 
        /* The costs below are hard coded to use a scaling factor of 16.  */
-       BUILD_BUG_ON(LZX_BIT_COST != 16);
+       STATIC_ASSERT(LZX_BIT_COST == 16);
 
        /*
         * Heuristics:
 
        /*
         * Heuristics:
@@ -1734,7 +1734,7 @@ lzx_find_longest_repeat_offset_match(const u8 * const in_next,
                                     struct lzx_lru_queue queue,
                                     unsigned *rep_max_idx_ret)
 {
                                     struct lzx_lru_queue queue,
                                     unsigned *rep_max_idx_ret)
 {
-       BUILD_BUG_ON(LZX_NUM_RECENT_OFFSETS != 3);
+       STATIC_ASSERT(LZX_NUM_RECENT_OFFSETS == 3);
        LZX_ASSERT(bytes_remaining >= 2);
 
        const unsigned max_len = min(bytes_remaining, LZX_MAX_MATCH_LEN);
        LZX_ASSERT(bytes_remaining >= 2);
 
        const unsigned max_len = min(bytes_remaining, LZX_MAX_MATCH_LEN);
index a8fbcd7d5e8325542537730ec7fef328754c53a8..687420a9a75d8c4e6042e32a13556e051c8dcbc8 100644 (file)
@@ -498,7 +498,7 @@ lzx_decompress_block(int block_type, u8 * const out_begin,
                        match_offset -= LZX_OFFSET_ADJUSTMENT;
 
                        /* Update the match offset LRU queue.  */
                        match_offset -= LZX_OFFSET_ADJUSTMENT;
 
                        /* Update the match offset LRU queue.  */
-                       BUILD_BUG_ON(LZX_NUM_RECENT_OFFSETS != 3);
+                       STATIC_ASSERT(LZX_NUM_RECENT_OFFSETS == 3);
                        queue->R[2] = queue->R[1];
                        queue->R[1] = queue->R[0];
                        queue->R[0] = match_offset;
                        queue->R[2] = queue->R[1];
                        queue->R[1] = queue->R[0];
                        queue->R[0] = match_offset;
index 03eb122edb693e9192c124839b7483603962f1ce..2b2c107b2cd2198ba40c222db43253eead799b7e 100644 (file)
@@ -689,7 +689,7 @@ attach_branch(struct wim_dentry *branch, const tchar *target_tstr,
        if (ret)
                goto out_free_branch;
 
        if (ret)
                goto out_free_branch;
 
-       BUILD_BUG_ON(WIM_PATH_SEPARATOR != OS_PREFERRED_PATH_SEPARATOR);
+       STATIC_ASSERT(WIM_PATH_SEPARATOR == OS_PREFERRED_PATH_SEPARATOR);
        ret = dentry_set_name(branch, path_basename(target_tstr));
        if (ret)
                goto out_free_target;
        ret = dentry_set_name(branch, path_basename(target_tstr));
        if (ret)
                goto out_free_target;
index 67798da3fd02f0deefc8591fd915f98509246a67..d4643d67e516ff2a9392a978ae0aa855105d674d 100644 (file)
@@ -187,8 +187,8 @@ query_partition_and_disk_info(const wchar_t *path,
        }
 
        if (part_info->PartitionStyle == PARTITION_STYLE_GPT) {
        }
 
        if (part_info->PartitionStyle == PARTITION_STYLE_GPT) {
-               BUILD_BUG_ON(sizeof(part_info->Gpt.PartitionId) !=
-                            sizeof(drive_info->Gpt.DiskId));
+               STATIC_ASSERT(sizeof(part_info->Gpt.PartitionId) ==
+                             sizeof(drive_info->Gpt.DiskId));
                if (!memcmp(&part_info->Gpt.PartitionId,
                            &drive_info->Gpt.DiskId,
                            sizeof(drive_info->Gpt.DiskId)))
                if (!memcmp(&part_info->Gpt.PartitionId,
                            &drive_info->Gpt.DiskId,
                            sizeof(drive_info->Gpt.DiskId)))
@@ -395,7 +395,7 @@ fill_in_wimoverlay_dat(u8 *buf,
        new_entry_1->entry_2_length = new_entry_2_size;
        new_entry_1->wim_type = WIM_BOOT_NOT_OS_WIM;
        new_entry_1->wim_index = image;
        new_entry_1->entry_2_length = new_entry_2_size;
        new_entry_1->wim_type = WIM_BOOT_NOT_OS_WIM;
        new_entry_1->wim_index = image;
-       BUILD_BUG_ON(sizeof(new_entry_1->guid) != GUID_SIZE);
+       STATIC_ASSERT(sizeof(new_entry_1->guid) == GUID_SIZE);
        copy_guid(new_entry_1->guid, wim_guid);
 
        p += sizeof(struct WimOverlay_dat_entry_1);
        copy_guid(new_entry_1->guid, wim_guid);
 
        p += sizeof(struct WimOverlay_dat_entry_1);
@@ -438,21 +438,21 @@ fill_in_wimoverlay_dat(u8 *buf,
                new_entry_2->disk.mbr.padding[1] = 0x00000000;
                new_entry_2->disk.mbr.padding[2] = 0x00000000;
        } else {
                new_entry_2->disk.mbr.padding[1] = 0x00000000;
                new_entry_2->disk.mbr.padding[2] = 0x00000000;
        } else {
-               BUILD_BUG_ON(sizeof(new_entry_2->partition.gpt.part_unique_guid) !=
-                            sizeof(part_info->Gpt.PartitionId));
+               STATIC_ASSERT(sizeof(new_entry_2->partition.gpt.part_unique_guid) ==
+                             sizeof(part_info->Gpt.PartitionId));
                memcpy(new_entry_2->partition.gpt.part_unique_guid,
                       &part_info->Gpt.PartitionId,
                       sizeof(part_info->Gpt.PartitionId));
                new_entry_2->partition_table_type = WIMOVERLAY_PARTITION_TYPE_GPT;
 
                memcpy(new_entry_2->partition.gpt.part_unique_guid,
                       &part_info->Gpt.PartitionId,
                       sizeof(part_info->Gpt.PartitionId));
                new_entry_2->partition_table_type = WIMOVERLAY_PARTITION_TYPE_GPT;
 
-               BUILD_BUG_ON(sizeof(new_entry_2->disk.gpt.disk_guid) !=
-                            sizeof(disk_info->Gpt.DiskId));
+               STATIC_ASSERT(sizeof(new_entry_2->disk.gpt.disk_guid) ==
+                             sizeof(disk_info->Gpt.DiskId));
                memcpy(new_entry_2->disk.gpt.disk_guid,
                       &disk_info->Gpt.DiskId,
                       sizeof(disk_info->Gpt.DiskId));
 
                memcpy(new_entry_2->disk.gpt.disk_guid,
                       &disk_info->Gpt.DiskId,
                       sizeof(disk_info->Gpt.DiskId));
 
-               BUILD_BUG_ON(sizeof(new_entry_2->disk.gpt.disk_guid) !=
-                            sizeof(new_entry_2->partition.gpt.part_unique_guid));
+               STATIC_ASSERT(sizeof(new_entry_2->disk.gpt.disk_guid) ==
+                             sizeof(new_entry_2->partition.gpt.part_unique_guid));
        }
        new_entry_2->unknown_0x58[0] = 0x00000000;
        new_entry_2->unknown_0x58[1] = 0x00000000;
        }
        new_entry_2->unknown_0x58[0] = 0x00000000;
        new_entry_2->unknown_0x58[1] = 0x00000000;
@@ -1135,9 +1135,9 @@ wimboot_set_pointer(HANDLE h,
                        struct wim_provider_rpdata wim_info;
                } in;
 
                        struct wim_provider_rpdata wim_info;
                } in;
 
-               BUILD_BUG_ON(sizeof(in) != 8 +
-                            sizeof(struct wof_external_info) +
-                            sizeof(struct wim_provider_rpdata));
+               STATIC_ASSERT(sizeof(in) == 8 +
+                             sizeof(struct wof_external_info) +
+                             sizeof(struct wim_provider_rpdata));
 
                in.hdr.rptag = WIM_IO_REPARSE_TAG_WOF;
                in.hdr.rpdatalen = sizeof(in) - sizeof(in.hdr);
 
                in.hdr.rptag = WIM_IO_REPARSE_TAG_WOF;
                in.hdr.rpdatalen = sizeof(in) - sizeof(in.hdr);
index 0367719558a6d9a747b1b284f71672b5d5f41d77..c030ba53b5fa99a23a4e7cc0ac3952c635a4f035 100644 (file)
@@ -352,7 +352,7 @@ load_prepopulate_pats(struct win32_apply_ctx *ctx)
                                LOAD_TEXT_FILE_REMOVE_QUOTES |
                                        LOAD_TEXT_FILE_NO_WARNINGS,
                                mangle_pat);
                                LOAD_TEXT_FILE_REMOVE_QUOTES |
                                        LOAD_TEXT_FILE_NO_WARNINGS,
                                mangle_pat);
-       BUILD_BUG_ON(OS_PREFERRED_PATH_SEPARATOR != WIM_PATH_SEPARATOR);
+       STATIC_ASSERT(OS_PREFERRED_PATH_SEPARATOR == WIM_PATH_SEPARATOR);
        FREE(buf);
        if (ret) {
                FREE(s);
        FREE(buf);
        if (ret) {
                FREE(s);
index b2e687a8012da94b81dbb19536cc42536b5bfae6..b595c875e08e08e80313aa3bd2e363e8577df2d3 100644 (file)
@@ -548,9 +548,9 @@ end_chunk_table(struct write_blobs_ctx *ctx, u64 res_actual_size,
                        hdr.chunk_size = cpu_to_le32(ctx->out_chunk_size);
                        hdr.compression_format = cpu_to_le32(ctx->out_ctype);
 
                        hdr.chunk_size = cpu_to_le32(ctx->out_chunk_size);
                        hdr.compression_format = cpu_to_le32(ctx->out_ctype);
 
-                       BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_XPRESS != 1);
-                       BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_LZX != 2);
-                       BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_LZMS != 3);
+                       STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_XPRESS == 1);
+                       STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_LZX == 2);
+                       STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_LZMS == 3);
 
                        ret = full_pwrite(ctx->out_fd, &hdr, sizeof(hdr),
                                          chunk_table_offset - sizeof(hdr));
 
                        ret = full_pwrite(ctx->out_fd, &hdr, sizeof(hdr),
                                          chunk_table_offset - sizeof(hdr));