summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2015-10-13 17:17:34 +0200
committerDenys Vlasenko2015-10-13 17:17:34 +0200
commit7b85ec30b5941f0b90c48a990f2f6840aca87bce (patch)
tree3565032bf3f34eeea195258d9d4edc9f01480e6e
parent4d0c1ea4784c9844f8468d97ca5c26d3c70f9921 (diff)
downloadbusybox-7b85ec30b5941f0b90c48a990f2f6840aca87bce.zip
busybox-7b85ec30b5941f0b90c48a990f2f6840aca87bce.tar.gz
*: more BUILD_BUG_ON conversions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/libarchive/decompress_gunzip.c5
-rw-r--r--editors/sed.c10
-rw-r--r--findutils/find.c4
-rw-r--r--findutils/grep.c4
-rw-r--r--miscutils/hdparm.c7
-rw-r--r--miscutils/taskset.c6
-rw-r--r--networking/inetd.c4
-rw-r--r--networking/nbd-client.c5
-rw-r--r--networking/telnet.c4
-rw-r--r--procps/top.c9
10 files changed, 22 insertions, 36 deletions
diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c
index 1360abe..7b6f459 100644
--- a/archival/libarchive/decompress_gunzip.c
+++ b/archival/libarchive/decompress_gunzip.c
@@ -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
diff --git a/editors/sed.c b/editors/sed.c
index 7bbf820..a8c3538 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -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;
+
+ BUILD_BUG_ON(sizeof(cmd_letters)-1 != IDX_nul);
- unsigned idx = strchrnul(cmd_letters, sed_cmd->cmd) - cmd_letters;
+ idx = strchrnul(cmd_letters, sed_cmd->cmd) - cmd_letters;
/* handle (s)ubstitution command */
if (idx == IDX_s) {
diff --git a/findutils/find.c b/findutils/find.c
index bd7ccc3..5bd7535 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -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;) \
diff --git a/findutils/grep.c b/findutils/grep.c
index b962138..10b6927 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -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
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index 9c486e7..8e201ac 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -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 */
diff --git a/miscutils/taskset.c b/miscutils/taskset.c
index 2646e1d..100b1d9 100644
--- a/miscutils/taskset.c
+++ b/miscutils/taskset.c
@@ -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
*/
diff --git a/networking/inetd.c b/networking/inetd.c
index dce5a08..243165a 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -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"; \
diff --git a/networking/nbd-client.c b/networking/nbd-client.c
index a601430..70869d6 100644
--- a/networking/nbd-client.c
+++ b/networking/nbd-client.c
@@ -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)
diff --git a/networking/telnet.c b/networking/telnet.c
index 3bb6fb1..944cf1b 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -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)
diff --git a/procps/top.c b/procps/top.c
index 3d67c3c..9a3f171 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -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),