There are now two remaining warnings.

Robin Farine robin.farine at terminus.org
Wed Sep 7 18:34:09 UTC 2005


On Wed September 7 2005 14:41, Rainer Weikusat wrote:

> 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 (sole exception is char), which
> means that the compiler may assume that the value of 'aligned'
> does not change due to indirect accesses (ie through pointers)
> except if the pointer is an u32 * (or a char *).

And how about this? If I understand the constraints on simple 
assignment correctly ...

--- orig/networking/udhcp/options.c
+++ mod/networking/udhcp/options.c
@@ -150,13 +150,10 @@
 	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;
+	void *alignedp = &aligned;
+	uint8_t *u8 = alignedp;
+	uint16_t *u16 = alignedp;
 
 	for (i = 0; dhcp_options[i].code; i++)
 		if (dhcp_options[i].code == code) {
@@ -174,7 +171,7 @@
 	switch (length) {
 		case 1: *u8 =  data; break;
 		case 2: *u16 = data; break;
-		case 4: *u32 = data; break;
+		case 4: aligned = data; break;
 	}
 	memcpy(option + 2, &aligned, length);
 	return add_option_string(optionptr, option);



More information about the busybox mailing list