aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-02-04 18:41:18 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-02-04 18:41:18 +0100
commit12ca080a1ca8dfd0aeac54485451b906a7e61b16 (patch)
treeabb273fb03a73bc9c20d05f9128bdfd9bfe55e55
parent98a4c7cf3d799ab953cb77e8b34597c73e3e7335 (diff)
downloadbusybox-w32-12ca080a1ca8dfd0aeac54485451b906a7e61b16.tar.gz
busybox-w32-12ca080a1ca8dfd0aeac54485451b906a7e61b16.tar.bz2
busybox-w32-12ca080a1ca8dfd0aeac54485451b906a7e61b16.zip
*: eliminate more aliasing warnings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/platform.h12
-rw-r--r--libbb/udp_io.c12
-rw-r--r--networking/ipcalc.c44
-rw-r--r--networking/udhcp/arpping.c3
-rw-r--r--util-linux/mkswap.c2
-rw-r--r--util-linux/volume_id/linux_raid.c3
6 files changed, 40 insertions, 36 deletions
diff --git a/include/platform.h b/include/platform.h
index ab4402e79..dcc61a77b 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -201,10 +201,14 @@
201 * a lvalue. This makes it more likely to not swap them by mistake 201 * a lvalue. This makes it more likely to not swap them by mistake
202 */ 202 */
203#if defined(i386) || defined(__x86_64__) 203#if defined(i386) || defined(__x86_64__)
204# define move_from_unaligned_int(v, intp) ((v) = *(int*)(intp)) 204# include <stdint.h>
205# define move_from_unaligned16(v, u16p) ((v) = *(uint16_t*)(u16p)) 205typedef int bb__aliased_int FIX_ALIASING;
206# define move_from_unaligned32(v, u32p) ((v) = *(uint32_t*)(u32p)) 206typedef uint16_t bb__aliased_uint16_t FIX_ALIASING;
207# define move_to_unaligned32(u32p, v) (*(uint32_t*)(u32p) = (v)) 207typedef uint32_t bb__aliased_uint32_t FIX_ALIASING;
208# define move_from_unaligned_int(v, intp) ((v) = *(bb__aliased_int*)(intp))
209# define move_from_unaligned16(v, u16p) ((v) = *(bb__aliased_uint16_t*)(u16p))
210# define move_from_unaligned32(v, u32p) ((v) = *(bb__aliased_uint32_t*)(u32p))
211# define move_to_unaligned32(u32p, v) (*(bb__aliased_uint32_t*)(u32p) = (v))
208/* #elif ... - add your favorite arch today! */ 212/* #elif ... - add your favorite arch today! */
209#else 213#else
210/* performs reasonably well (gcc usually inlines memcpy here) */ 214/* performs reasonably well (gcc usually inlines memcpy here) */
diff --git a/libbb/udp_io.c b/libbb/udp_io.c
index d9375eac2..24237be99 100644
--- a/libbb/udp_io.c
+++ b/libbb/udp_io.c
@@ -152,24 +152,24 @@ recv_from_to(int fd, void *buf, size_t len, int flags,
152 if (cmsgptr->cmsg_level == IPPROTO_IP 152 if (cmsgptr->cmsg_level == IPPROTO_IP
153 && cmsgptr->cmsg_type == IP_PKTINFO 153 && cmsgptr->cmsg_type == IP_PKTINFO
154 ) { 154 ) {
155# define pktinfo(cmsgptr) ( (struct in_pktinfo*)(CMSG_DATA(cmsgptr)) ) 155 const int IPI_ADDR_OFF = offsetof(struct in_pktinfo, ipi_addr);
156 to->sa_family = AF_INET; 156 to->sa_family = AF_INET;
157 /*# define pktinfo(cmsgptr) ( (struct in_pktinfo*)(CMSG_DATA(cmsgptr)) )*/
157 /*to4->sin_addr = pktinfo(cmsgptr)->ipi_addr; - may be unaligned */ 158 /*to4->sin_addr = pktinfo(cmsgptr)->ipi_addr; - may be unaligned */
158 memcpy(&to4->sin_addr, &pktinfo(cmsgptr)->ipi_addr, sizeof(to4->sin_addr)); 159 memcpy(&to4->sin_addr, (char*)(CMSG_DATA(cmsgptr)) + IPI_ADDR_OFF, sizeof(to4->sin_addr));
159 /*to4->sin_port = 123; - this data is not supplied by kernel */ 160 /*to4->sin_port = 123; - this data is not supplied by kernel */
160# undef pktinfo
161 break; 161 break;
162 } 162 }
163# if ENABLE_FEATURE_IPV6 && defined(IPV6_PKTINFO) 163# if ENABLE_FEATURE_IPV6 && defined(IPV6_PKTINFO)
164 if (cmsgptr->cmsg_level == IPPROTO_IPV6 164 if (cmsgptr->cmsg_level == IPPROTO_IPV6
165 && cmsgptr->cmsg_type == IPV6_PKTINFO 165 && cmsgptr->cmsg_type == IPV6_PKTINFO
166 ) { 166 ) {
167# define pktinfo(cmsgptr) ( (struct in6_pktinfo*)(CMSG_DATA(cmsgptr)) ) 167 const int IPI6_ADDR_OFF = offsetof(struct in6_pktinfo, ipi6_addr);
168 to->sa_family = AF_INET6; 168 to->sa_family = AF_INET6;
169 /*# define pktinfo(cmsgptr) ( (struct in6_pktinfo*)(CMSG_DATA(cmsgptr)) )*/
169 /*to6->sin6_addr = pktinfo(cmsgptr)->ipi6_addr; - may be unaligned */ 170 /*to6->sin6_addr = pktinfo(cmsgptr)->ipi6_addr; - may be unaligned */
170 memcpy(&to6->sin6_addr, &pktinfo(cmsgptr)->ipi6_addr, sizeof(to6->sin6_addr)); 171 memcpy(&to6->sin6_addr, (char*)(CMSG_DATA(cmsgptr)) + IPI6_ADDR_OFF, sizeof(to6->sin6_addr));
171 /*to6->sin6_port = 123; */ 172 /*to6->sin6_port = 123; */
172# undef pktinfo
173 break; 173 break;
174 } 174 }
175# endif 175# endif
diff --git a/networking/ipcalc.c b/networking/ipcalc.c
index 18abc12eb..78558495e 100644
--- a/networking/ipcalc.c
+++ b/networking/ipcalc.c
@@ -75,29 +75,34 @@ int get_prefix(unsigned long netmask);
75#endif 75#endif
76 76
77int ipcalc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 77int ipcalc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
78int ipcalc_main(int argc, char **argv) 78int ipcalc_main(int argc UNUSED_PARAM, char **argv)
79{ 79{
80 unsigned opt; 80 unsigned opt;
81 int have_netmask = 0; 81 bool have_netmask = 0;
82 in_addr_t netmask, broadcast, network, ipaddr; 82 struct in_addr s_netmask, s_broadcast, s_network, s_ipaddr;
83 struct in_addr a; 83 /* struct in_addr { in_addr_t s_addr; } and in_addr_t
84 * (which in turn is just a typedef to uint32_t)
85 * are essentially the same type. A few macros for less verbosity: */
86#define netmask (s_netmask.s_addr)
87#define broadcast (s_broadcast.s_addr)
88#define network (s_network.s_addr)
89#define ipaddr (s_ipaddr.s_addr)
84 char *ipstr; 90 char *ipstr;
85 91
86#if ENABLE_FEATURE_IPCALC_LONG_OPTIONS 92#if ENABLE_FEATURE_IPCALC_LONG_OPTIONS
87 applet_long_options = ipcalc_longopts; 93 applet_long_options = ipcalc_longopts;
88#endif 94#endif
89 opt = getopt32(argv, "mbn" IF_FEATURE_IPCALC_FANCY("phs")); 95 opt = getopt32(argv, "mbn" IF_FEATURE_IPCALC_FANCY("phs"));
90 argc -= optind;
91 argv += optind; 96 argv += optind;
97 if (opt & SILENT)
98 logmode = LOGMODE_NONE; /* suppress error_msg() output */
92 if (opt & (BROADCAST | NETWORK | NETPREFIX)) { 99 if (opt & (BROADCAST | NETWORK | NETPREFIX)) {
93 if (argc > 2 || argc <= 0) 100 if (!argv[0] || !argv[1] || argv[2])
94 bb_show_usage(); 101 bb_show_usage();
95 } else { 102 } else {
96 if (argc != 1) 103 if (!argv[0] || argv[1])
97 bb_show_usage(); 104 bb_show_usage();
98 } 105 }
99 if (opt & SILENT)
100 logmode = LOGMODE_NONE; /* Suppress error_msg() output */
101 106
102 ipstr = argv[0]; 107 ipstr = argv[0];
103 if (ENABLE_FEATURE_IPCALC_FANCY) { 108 if (ENABLE_FEATURE_IPCALC_FANCY) {
@@ -108,8 +113,7 @@ int ipcalc_main(int argc, char **argv)
108 113
109 while (*prefixstr) { 114 while (*prefixstr) {
110 if (*prefixstr == '/') { 115 if (*prefixstr == '/') {
111 *prefixstr = (char)0; 116 *prefixstr++ = '\0';
112 prefixstr++;
113 if (*prefixstr) { 117 if (*prefixstr) {
114 unsigned msk; 118 unsigned msk;
115 netprefix = xatoul_range(prefixstr, 0, 32); 119 netprefix = xatoul_range(prefixstr, 0, 32);
@@ -130,42 +134,36 @@ int ipcalc_main(int argc, char **argv)
130 prefixstr++; 134 prefixstr++;
131 } 135 }
132 } 136 }
133 ipaddr = inet_aton(ipstr, &a);
134 137
135 if (ipaddr == 0) { 138 if (inet_aton(ipstr, &s_ipaddr) == 0) {
136 bb_error_msg_and_die("bad IP address: %s", argv[0]); 139 bb_error_msg_and_die("bad IP address: %s", argv[0]);
137 } 140 }
138 ipaddr = a.s_addr;
139 141
140 if (argc == 2) { 142 if (argv[1]) {
141 if (ENABLE_FEATURE_IPCALC_FANCY && have_netmask) { 143 if (ENABLE_FEATURE_IPCALC_FANCY && have_netmask) {
142 bb_error_msg_and_die("use prefix or netmask, not both"); 144 bb_error_msg_and_die("use prefix or netmask, not both");
143 } 145 }
144 146 if (inet_aton(argv[1], &s_netmask) == 0) {
145 netmask = inet_aton(argv[1], &a);
146 if (netmask == 0) {
147 bb_error_msg_and_die("bad netmask: %s", argv[1]); 147 bb_error_msg_and_die("bad netmask: %s", argv[1]);
148 } 148 }
149 netmask = a.s_addr;
150 } else { 149 } else {
151
152 /* JHC - If the netmask wasn't provided then calculate it */ 150 /* JHC - If the netmask wasn't provided then calculate it */
153 if (!ENABLE_FEATURE_IPCALC_FANCY || !have_netmask) 151 if (!ENABLE_FEATURE_IPCALC_FANCY || !have_netmask)
154 netmask = get_netmask(ipaddr); 152 netmask = get_netmask(ipaddr);
155 } 153 }
156 154
157 if (opt & NETMASK) { 155 if (opt & NETMASK) {
158 printf("NETMASK=%s\n", inet_ntoa((*(struct in_addr *) &netmask))); 156 printf("NETMASK=%s\n", inet_ntoa(s_netmask));
159 } 157 }
160 158
161 if (opt & BROADCAST) { 159 if (opt & BROADCAST) {
162 broadcast = (ipaddr & netmask) | ~netmask; 160 broadcast = (ipaddr & netmask) | ~netmask;
163 printf("BROADCAST=%s\n", inet_ntoa((*(struct in_addr *) &broadcast))); 161 printf("BROADCAST=%s\n", inet_ntoa(s_broadcast));
164 } 162 }
165 163
166 if (opt & NETWORK) { 164 if (opt & NETWORK) {
167 network = ipaddr & netmask; 165 network = ipaddr & netmask;
168 printf("NETWORK=%s\n", inet_ntoa((*(struct in_addr *) &network))); 166 printf("NETWORK=%s\n", inet_ntoa(s_network));
169 } 167 }
170 168
171 if (ENABLE_FEATURE_IPCALC_FANCY) { 169 if (ENABLE_FEATURE_IPCALC_FANCY) {
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c
index 548796e2b..cf18153f7 100644
--- a/networking/udhcp/arpping.c
+++ b/networking/udhcp/arpping.c
@@ -87,6 +87,7 @@ int FAST_FUNC arpping(uint32_t test_nip,
87 /* wait for arp reply, and check it */ 87 /* wait for arp reply, and check it */
88 timeout_ms = 2000; 88 timeout_ms = 2000;
89 do { 89 do {
90 typedef uint32_t aliased_uint32_t FIX_ALIASING;
90 int r; 91 int r;
91 unsigned prevTime = monotonic_ms(); 92 unsigned prevTime = monotonic_ms();
92 93
@@ -107,7 +108,7 @@ int FAST_FUNC arpping(uint32_t test_nip,
107 && arp.operation == htons(ARPOP_REPLY) 108 && arp.operation == htons(ARPOP_REPLY)
108 /* don't check it: Linux doesn't return proper tHaddr (fixed in 2.6.24?) */ 109 /* don't check it: Linux doesn't return proper tHaddr (fixed in 2.6.24?) */
109 /* && memcmp(arp.tHaddr, from_mac, 6) == 0 */ 110 /* && memcmp(arp.tHaddr, from_mac, 6) == 0 */
110 && *((uint32_t *) arp.sInaddr) == test_nip 111 && *(aliased_uint32_t*)arp.sInaddr == test_nip
111 ) { 112 ) {
112 /* if ARP source MAC matches safe_mac 113 /* if ARP source MAC matches safe_mac
113 * (which is client's MAC), then it's not a conflict 114 * (which is client's MAC), then it's not a conflict
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index 949c71a78..7e32d91ed 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -65,7 +65,7 @@ struct swap_header_v1 {
65 uint32_t padding[117]; /* 11..127 */ 65 uint32_t padding[117]; /* 11..127 */
66 uint32_t badpages[1]; /* 128 */ 66 uint32_t badpages[1]; /* 128 */
67 /* total 129 32-bit words in 2nd kilobyte */ 67 /* total 129 32-bit words in 2nd kilobyte */
68}; 68} FIX_ALIASING;
69 69
70#define NWORDS 129 70#define NWORDS 129
71#define hdr ((struct swap_header_v1*)bb_common_bufsiz1) 71#define hdr ((struct swap_header_v1*)bb_common_bufsiz1)
diff --git a/util-linux/volume_id/linux_raid.c b/util-linux/volume_id/linux_raid.c
index d1bf0c308..e1c86369d 100644
--- a/util-linux/volume_id/linux_raid.c
+++ b/util-linux/volume_id/linux_raid.c
@@ -44,6 +44,7 @@ struct mdp_super_block {
44 44
45int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id /*,uint64_t off*/, uint64_t size) 45int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id /*,uint64_t off*/, uint64_t size)
46{ 46{
47 typedef uint32_t aliased_uint32_t FIX_ALIASING;
47#define off ((uint64_t)0) 48#define off ((uint64_t)0)
48 uint64_t sboff; 49 uint64_t sboff;
49 uint8_t uuid[16]; 50 uint8_t uuid[16];
@@ -63,7 +64,7 @@ int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id /*,uint64_t off*/,
63 if (mdp->md_magic != cpu_to_le32(MD_MAGIC)) 64 if (mdp->md_magic != cpu_to_le32(MD_MAGIC))
64 return -1; 65 return -1;
65 66
66 *(uint32_t*)uuid = mdp->set_uuid0; 67 *(aliased_uint32_t*)uuid = mdp->set_uuid0;
67 memcpy(&uuid[4], &mdp->set_uuid1, 12); 68 memcpy(&uuid[4], &mdp->set_uuid1, 12);
68 volume_id_set_uuid(id, uuid, UUID_DCE); 69 volume_id_set_uuid(id, uuid, UUID_DCE);
69 70