aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-10-13 14:50:20 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2015-10-13 14:50:20 +0200
commitab3964db4e75e34f6f9347406c5fd2bced04f2dd (patch)
tree92113e4a008338ed8534858db97d3a5e09dc210b /networking
parentf7ad927c2059ef9cd1cd6befeb43f26b92f6369f (diff)
downloadbusybox-w32-ab3964db4e75e34f6f9347406c5fd2bced04f2dd.tar.gz
busybox-w32-ab3964db4e75e34f6f9347406c5fd2bced04f2dd.tar.bz2
busybox-w32-ab3964db4e75e34f6f9347406c5fd2bced04f2dd.zip
libbb: introduce kernel-style BUILD_BUG_ON()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r--networking/ftpgetput.c7
-rw-r--r--networking/isrv.c4
-rw-r--r--networking/ping.c8
-rw-r--r--networking/tc.c7
-rw-r--r--networking/tftp.c7
5 files changed, 12 insertions, 21 deletions
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index 8283366cc..b398bc874 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -62,9 +62,6 @@ struct globals {
62} FIX_ALIASING; 62} FIX_ALIASING;
63#define G (*(struct globals*)&bb_common_bufsiz1) 63#define G (*(struct globals*)&bb_common_bufsiz1)
64enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) }; 64enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) };
65struct BUG_G_too_big {
66 char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1];
67};
68#define user (G.user ) 65#define user (G.user )
69#define password (G.password ) 66#define password (G.password )
70#define lsa (G.lsa ) 67#define lsa (G.lsa )
@@ -72,7 +69,9 @@ struct BUG_G_too_big {
72#define verbose_flag (G.verbose_flag ) 69#define verbose_flag (G.verbose_flag )
73#define do_continue (G.do_continue ) 70#define do_continue (G.do_continue )
74#define buf (G.buf ) 71#define buf (G.buf )
75#define INIT_G() do { } while (0) 72#define INIT_G() do { \
73 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
74} while (0)
76 75
77 76
78static void ftp_die(const char *msg) NORETURN; 77static void ftp_die(const char *msg) NORETURN;
diff --git a/networking/isrv.c b/networking/isrv.c
index 1c6491edd..3673db715 100644
--- a/networking/isrv.c
+++ b/networking/isrv.c
@@ -194,7 +194,6 @@ static void handle_accept(isrv_state_t *state, int fd)
194 remove_peer(state, n); /* unsuccesful peer start */ 194 remove_peer(state, n); /* unsuccesful peer start */
195} 195}
196 196
197void BUG_sizeof_fd_set_is_strange(void);
198static void handle_fd_set(isrv_state_t *state, fd_set *fds, int (*h)(int, void **)) 197static void handle_fd_set(isrv_state_t *state, fd_set *fds, int (*h)(int, void **))
199{ 198{
200 enum { LONG_CNT = sizeof(fd_set) / sizeof(long) }; 199 enum { LONG_CNT = sizeof(fd_set) / sizeof(long) };
@@ -203,8 +202,7 @@ static void handle_fd_set(isrv_state_t *state, fd_set *fds, int (*h)(int, void *
203 /* need to know value at _the beginning_ of this routine */ 202 /* need to know value at _the beginning_ of this routine */
204 int fd_cnt = FD_COUNT; 203 int fd_cnt = FD_COUNT;
205 204
206 if (LONG_CNT * sizeof(long) != sizeof(fd_set)) 205 BUILD_BUG_ON(LONG_CNT * sizeof(long) != sizeof(fd_set));
207 BUG_sizeof_fd_set_is_strange();
208 206
209 fds_pos = 0; 207 fds_pos = 0;
210 while (1) { 208 while (1) {
diff --git a/networking/ping.c b/networking/ping.c
index dcbf19682..0eb1ae799 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -396,10 +396,8 @@ struct globals {
396#define dotted (G.dotted ) 396#define dotted (G.dotted )
397#define pingaddr (G.pingaddr ) 397#define pingaddr (G.pingaddr )
398#define rcvd_tbl (G.rcvd_tbl ) 398#define rcvd_tbl (G.rcvd_tbl )
399void BUG_ping_globals_too_big(void);
400#define INIT_G() do { \ 399#define INIT_G() do { \
401 if (sizeof(G) > COMMON_BUFSIZE) \ 400 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
402 BUG_ping_globals_too_big(); \
403 datalen = DEFDATALEN; \ 401 datalen = DEFDATALEN; \
404 timeout = MAXWAIT; \ 402 timeout = MAXWAIT; \
405 tmin = UINT_MAX; \ 403 tmin = UINT_MAX; \
@@ -732,7 +730,6 @@ static void ping4(len_and_sockaddr *lsa)
732 } 730 }
733} 731}
734#if ENABLE_PING6 732#if ENABLE_PING6
735extern int BUG_bad_offsetof_icmp6_cksum(void);
736static void ping6(len_and_sockaddr *lsa) 733static void ping6(len_and_sockaddr *lsa)
737{ 734{
738 int sockopt; 735 int sockopt;
@@ -769,8 +766,7 @@ static void ping6(len_and_sockaddr *lsa)
769 setsockopt_SOL_SOCKET_int(pingsock, SO_RCVBUF, sockopt); 766 setsockopt_SOL_SOCKET_int(pingsock, SO_RCVBUF, sockopt);
770 767
771 sockopt = offsetof(struct icmp6_hdr, icmp6_cksum); 768 sockopt = offsetof(struct icmp6_hdr, icmp6_cksum);
772 if (offsetof(struct icmp6_hdr, icmp6_cksum) != 2) 769 BUILD_BUG_ON(offsetof(struct icmp6_hdr, icmp6_cksum) != 2);
773 BUG_bad_offsetof_icmp6_cksum();
774 setsockopt_int(pingsock, SOL_RAW, IPV6_CHECKSUM, sockopt); 770 setsockopt_int(pingsock, SOL_RAW, IPV6_CHECKSUM, sockopt);
775 771
776 /* request ttl info to be returned in ancillary data */ 772 /* request ttl info to be returned in ancillary data */
diff --git a/networking/tc.c b/networking/tc.c
index 76e2e8359..6d1fef993 100644
--- a/networking/tc.c
+++ b/networking/tc.c
@@ -64,15 +64,14 @@ struct globals {
64 uint32_t filter_proto; 64 uint32_t filter_proto;
65} FIX_ALIASING; 65} FIX_ALIASING;
66#define G (*(struct globals*)&bb_common_bufsiz1) 66#define G (*(struct globals*)&bb_common_bufsiz1)
67struct BUG_G_too_big {
68 char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1];
69};
70#define filter_ifindex (G.filter_ifindex) 67#define filter_ifindex (G.filter_ifindex)
71#define filter_qdisc (G.filter_qdisc) 68#define filter_qdisc (G.filter_qdisc)
72#define filter_parent (G.filter_parent) 69#define filter_parent (G.filter_parent)
73#define filter_prio (G.filter_prio) 70#define filter_prio (G.filter_prio)
74#define filter_proto (G.filter_proto) 71#define filter_proto (G.filter_proto)
75#define INIT_G() do { } while (0) 72#define INIT_G() do { \
73 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
74} while (0)
76 75
77/* Allocates a buffer containing the name of a class id. 76/* Allocates a buffer containing the name of a class id.
78 * The caller must free the returned memory. */ 77 * The caller must free the returned memory. */
diff --git a/networking/tftp.c b/networking/tftp.c
index 8ecd7bb6f..ad9308e52 100644
--- a/networking/tftp.c
+++ b/networking/tftp.c
@@ -129,10 +129,9 @@ struct globals {
129#endif 129#endif
130} FIX_ALIASING; 130} FIX_ALIASING;
131#define G (*(struct globals*)&bb_common_bufsiz1) 131#define G (*(struct globals*)&bb_common_bufsiz1)
132struct BUG_G_too_big { 132#define INIT_G() do { \
133 char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; 133 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
134}; 134} while (0)
135#define INIT_G() do { } while (0)
136 135
137#define G_error_pkt_reason (G.error_pkt[3]) 136#define G_error_pkt_reason (G.error_pkt[3])
138#define G_error_pkt_str ((char*)(G.error_pkt + 4)) 137#define G_error_pkt_str ((char*)(G.error_pkt + 4))