*: more BUILD_BUG_ON conversions

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2015-10-13 17:17:34 +02:00
parent 4d0c1ea478
commit 7b85ec30b5
10 changed files with 22 additions and 36 deletions

View File

@ -1118,9 +1118,8 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
uint8_t os_flags_UNUSED;
} PACKED formatted;
} header;
struct BUG_header {
char BUG_header[sizeof(header) == 8 ? 1 : -1];
};
BUILD_BUG_ON(sizeof(header) != 8);
/*
* Rewind bytebuffer. We use the beginning because the header has 8

View File

@ -162,10 +162,8 @@ struct globals {
} pipeline;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
struct BUG_G_too_big {
char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1];
};
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
G.sed_cmd_tail = &G.sed_cmd_head; \
} while (0)
@ -501,9 +499,11 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
IDX_rbrace,
IDX_nul
};
struct chk { char chk[sizeof(cmd_letters)-1 == IDX_nul ? 1 : -1]; };
unsigned idx;
unsigned idx = strchrnul(cmd_letters, sed_cmd->cmd) - cmd_letters;
BUILD_BUG_ON(sizeof(cmd_letters)-1 != IDX_nul);
idx = strchrnul(cmd_letters, sed_cmd->cmd) - cmd_letters;
/* handle (s)ubstitution command */
if (idx == IDX_s) {

View File

@ -423,9 +423,7 @@ struct globals {
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { \
struct G_sizecheck { \
char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \
}; \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \
IF_FEATURE_FIND_MAXDEPTH(G.minmaxdepth[1] = INT_MAX;) \

View File

@ -203,9 +203,7 @@ struct globals {
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { \
struct G_sizecheck { \
char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \
}; \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)
#define max_matches (G.max_matches )
#if !ENABLE_EXTRA_COMPAT

View File

@ -368,9 +368,6 @@ struct globals {
#endif
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
struct BUG_G_too_big {
char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1];
};
#define get_identity (G.get_identity )
#define get_geom (G.get_geom )
#define do_flush (G.do_flush )
@ -433,7 +430,9 @@ struct BUG_G_too_big {
#define hwif_data (G.hwif_data )
#define hwif_ctrl (G.hwif_ctrl )
#define hwif_irq (G.hwif_irq )
#define INIT_G() do { } while (0)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)
/* Busybox messages and functions */

View File

@ -75,12 +75,10 @@ static char *from_cpuset(cpu_set_t *mask)
#define TASKSET_PRINTF_MASK "%llx"
static unsigned long long from_cpuset(cpu_set_t *mask)
{
struct BUG_CPU_SETSIZE_is_too_small {
char BUG_CPU_SETSIZE_is_too_small[
CPU_SETSIZE < sizeof(int) ? -1 : 1];
};
char *p = (void*)mask;
BUILD_BUG_ON(CPU_SETSIZE < sizeof(int));
/* Take the least significant bits. Careful!
* Consider both CPU_SETSIZE=4 and CPU_SETSIZE=1024 cases
*/

View File

@ -329,9 +329,6 @@ struct globals {
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
enum { LINE_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line) };
struct BUG_G_too_big {
char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1];
};
#define rlim_ofile_cur (G.rlim_ofile_cur )
#define rlim_ofile (G.rlim_ofile )
#define serv_list (G.serv_list )
@ -352,6 +349,7 @@ struct BUG_G_too_big {
#define allsock (G.allsock )
#define line (G.line )
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
rlim_ofile_cur = OPEN_MAX; \
global_queuelen = 128; \
config_filename = "/etc/inetd.conf"; \

View File

@ -57,9 +57,8 @@ int nbdclient_main(int argc, char **argv)
uint32_t flags;
char data[124];
} nbd_header;
struct bug_check {
char c[offsetof(struct nbd_header_t, data) == 8+8+8+4 ? 1 : -1];
};
BUILD_BUG_ON(offsetof(struct nbd_header_t, data) != 8+8+8+4);
// Parse command line stuff (just a stub now)
if (argc != 4)

View File

@ -110,9 +110,7 @@ struct globals {
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { \
struct G_sizecheck { \
char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \
}; \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)

View File

@ -184,10 +184,6 @@ struct globals {
}; //FIX_ALIASING; - large code growth
enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) };
#define G (*(struct globals*)&bb_common_bufsiz1)
struct BUG_bad_size {
char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1];
char BUG_line_buf_too_small[LINE_BUF_SIZE > 80 ? 1 : -1];
};
#define top (G.top )
#define ntop (G.ntop )
#define sort_field (G.sort_field )
@ -204,7 +200,10 @@ struct BUG_bad_size {
#define num_cpus (G.num_cpus )
#define total_pcpu (G.total_pcpu )
#define line_buf (G.line_buf )
#define INIT_G() do { } while (0)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \
} while (0)
enum {
OPT_d = (1 << 0),