There are now two remaining warnings.
Robin Farine
robin.farine at terminus.org
Wed Sep 7 13:54:36 UTC 2005
On Wed September 7 2005 14:41, Rainer Weikusat wrote:
> Aurelien Jacobs <aurel at gnuage.org> writes:
> > On Wed, 7 Sep 2005 02:09:29 -0500
> >
> > Rob Landley <rob at landley.net> wrote:
> >> > /home/landley/busybox/busybox/networking/udhcp/options.c:160
> >> >: warning: dereferencing type-punned pointer will break
> >> > strict-aliasing rules
> >>
> >> This looks like an endianness problem to me. (What's wrong
> >> with doing this through &mask |value the way everybody else
> >> does it?)
> >
> > I think it's more related to alignment of different pointer
> > types.
>
> There is no need to speculate here, because the message means
> exactly what it says: As of C99, no objects of different types
> are allowed to alias each other
[...]
How about this speculation (because it is totally untested):
--- orig/networking/udhcp/options.c
+++ mod/networking/udhcp/options.c
@@ -150,13 +150,6 @@
char length = 0;
int i;
uint8_t option[2 + 4];
- uint8_t *u8;
- uint16_t *u16;
- uint32_t *u32;
- uint32_t aligned;
- u8 = (uint8_t *) &aligned;
- u16 = (uint16_t *) &aligned;
- u32 = &aligned;
for (i = 0; dhcp_options[i].code; i++)
if (dhcp_options[i].code == code) {
@@ -172,11 +165,17 @@
option[OPT_LEN] = length;
switch (length) {
- case 1: *u8 = data; break;
- case 2: *u16 = data; break;
- case 4: *u32 = data; break;
+ case 4:
+ option[5] = (uint8_t)data;
+ data >>= 8;
+ option[4] = (uint8_t)data;
+ data >>= 8;
+ case 2:
+ option[3] = (uint8_t)data;
+ data >>= 8;
+ case 1:
+ option[2] = (uint8_t)data;
}
- memcpy(option + 2, &aligned, length);
return add_option_string(optionptr, option);
}
More information about the busybox
mailing list