Browse code

- killed gcc 4.x "type-punned pointer will break strict-aliasing warnings" (warning season opened)

Andrei Pelinescu-Onciul authored on 07/12/2006 18:58:02
Showing 3 changed files
... ...
@@ -68,6 +68,7 @@ static inline int new_credentials(struct hdr_field* _h)
68 68
 int parse_credentials(struct hdr_field* _h)
69 69
 {
70 70
 	int res;
71
+	void** ph_parsed;
71 72
 
72 73
 	if (_h->parsed) {
73 74
 		return 0;  /* Already parsed */
... ...
@@ -85,7 +86,8 @@ int parse_credentials(struct hdr_field* _h)
85 86
 	res = parse_digest_cred(&(_h->body), &(((auth_body_t*)(_h->parsed))->digest));
86 87
 	
87 88
 	if (res != 0) {
88
-		free_credentials((auth_body_t**)&(_h->parsed));
89
+		ph_parsed=&_h->parsed;
90
+		free_credentials((auth_body_t**)ph_parsed);
89 91
 	}
90 92
 
91 93
 	return res;
... ...
@@ -56,7 +56,10 @@
56 56
  */
57 57
 void clean_hdr_field(struct hdr_field* hf)
58 58
 {
59
+	void** h_parsed;
60
+	
59 61
 	if (hf->parsed){
62
+		h_parsed=&hf->parsed; /*strict aliasing warnings workarround */
60 63
 		switch(hf->type){
61 64
 		case HDR_VIA_T:
62 65
 			free_via_list(hf->parsed);
... ...
@@ -78,22 +81,22 @@ void clean_hdr_field(struct hdr_field* hf)
78 81
 			break;
79 82
 
80 83
 		case HDR_SIPIFMATCH_T:
81
-			free_sipifmatch((str **)(&(hf->parsed)));
84
+			free_sipifmatch((str **)h_parsed);
82 85
 			break;
83 86
 
84 87
 		case HDR_CONTACT_T:
85
-			free_contact((contact_body_t**)(&(hf->parsed)));
88
+			free_contact((contact_body_t**)h_parsed);
86 89
 			break;
87 90
 
88 91
 		case HDR_MAXFORWARDS_T:
89 92
 			break;
90 93
 
91 94
 		case HDR_ROUTE_T:
92
-			free_rr((rr_t**)(&hf->parsed));
95
+			free_rr((rr_t**)h_parsed);
93 96
 			break;
94 97
 
95 98
 		case HDR_RECORDROUTE_T:
96
-			free_rr((rr_t**)(&hf->parsed));
99
+			free_rr((rr_t**)h_parsed);
97 100
 			break;
98 101
 
99 102
 		case HDR_CONTENTTYPE_T:
... ...
@@ -103,15 +106,15 @@ void clean_hdr_field(struct hdr_field* hf)
103 106
 			break;
104 107
 
105 108
 		case HDR_AUTHORIZATION_T:
106
-			free_credentials((auth_body_t**)(&(hf->parsed)));
109
+			free_credentials((auth_body_t**)h_parsed);
107 110
 			break;
108 111
 
109 112
 		case HDR_EXPIRES_T:
110
-			free_expires((exp_body_t**)(&(hf->parsed)));
113
+			free_expires((exp_body_t**)h_parsed);
111 114
 			break;
112 115
 
113 116
 		case HDR_PROXYAUTH_T:
114
-			free_credentials((auth_body_t**)(&(hf->parsed)));
117
+			free_credentials((auth_body_t**)h_parsed);
115 118
 			break;
116 119
 
117 120
 		case HDR_SUPPORTED_T:
... ...
@@ -130,7 +133,7 @@ void clean_hdr_field(struct hdr_field* hf)
130 133
 			break;
131 134
 
132 135
 		case HDR_EVENT_T:
133
-			free_event((event_t**)(&(hf->parsed)));
136
+			free_event((event_t**)h_parsed);
134 137
 			break;
135 138
 
136 139
 		case HDR_ACCEPT_T:
... ...
@@ -156,7 +159,7 @@ void clean_hdr_field(struct hdr_field* hf)
156 159
 			break;
157 160
 
158 161
 		case HDR_CONTENTDISPOSITION_T:
159
-			free_disposition( ((struct disposition**)(&hf->parsed)) );
162
+			free_disposition( ((struct disposition**)h_parsed));
160 163
 			break;
161 164
 
162 165
 		case HDR_DIVERSION_T:
... ...
@@ -172,7 +175,7 @@ void clean_hdr_field(struct hdr_field* hf)
172 175
 			break;
173 176
 		
174 177
 		case HDR_SUBSCRIPTION_STATE_T:
175
-			free_subscription_state((subscription_state_t**)(&hf->parsed));
178
+			free_subscription_state((subscription_state_t**)h_parsed);
176 179
 			break;
177 180
 
178 181
 		case HDR_SESSIONEXPIRES_T:
... ...
@@ -152,6 +152,7 @@ avp_t *create_avp (avp_flags_t flags, avp_name_t name, avp_value_t val)
152 152
 	struct str_int_data *sid;
153 153
 	struct str_str_data *ssd;
154 154
 	int len;
155
+	void** p_data;
155 156
 
156 157
 	if (name.s.s == 0 && name.s.len == 0) {
157 158
 		LOG(L_ERR,"ERROR:avp:add_avp: 0 ID or NULL NAME AVP!");
... ...
@@ -186,6 +187,7 @@ avp_t *create_avp (avp_flags_t flags, avp_name_t name, avp_value_t val)
186 187
 	avp->flags = flags;
187 188
 	avp->id = (flags&AVP_NAME_STR)? compute_ID(&name.s) : name.n ;
188 189
 	avp->next = NULL;
190
+	p_data=&avp->data; /* strict aliasing /type punning warnings workarround */
189 191
 
190 192
 	switch ( flags&(AVP_NAME_STR|AVP_VAL_STR) )
191 193
 	{
... ...
@@ -195,7 +197,7 @@ avp_t *create_avp (avp_flags_t flags, avp_name_t name, avp_value_t val)
195 197
 			break;
196 198
 		case AVP_NAME_STR:
197 199
 			/* avp type str, int value */
198
-			sid = (struct str_int_data*)&(avp->data);
200
+			sid = (struct str_int_data*)p_data;
199 201
 			sid->val = val.n;
200 202
 			sid->name.len =name.s.len;
201 203
 			sid->name.s = (char*)sid + sizeof(struct str_int_data);
... ...
@@ -204,7 +206,7 @@ avp_t *create_avp (avp_flags_t flags, avp_name_t name, avp_value_t val)
204 206
 			break;
205 207
 		case AVP_VAL_STR:
206 208
 			/* avp type ID, str value */
207
-			s = (str*)&(avp->data);
209
+			s = (str*)p_data;
208 210
 			s->len = val.s.len;
209 211
 			s->s = (char*)s + sizeof(str);
210 212
 			memcpy( s->s, val.s.s , s->len);
... ...
@@ -212,7 +214,7 @@ avp_t *create_avp (avp_flags_t flags, avp_name_t name, avp_value_t val)
212 214
 			break;
213 215
 		case AVP_NAME_STR|AVP_VAL_STR:
214 216
 			/* avp type str, str value */
215
-			ssd = (struct str_str_data*)&(avp->data);
217
+			ssd = (struct str_str_data*)p_data;
216 218
 			ssd->name.len = name.s.len;
217 219
 			ssd->name.s = (char*)ssd + sizeof(struct str_str_data);
218 220
 			memcpy( ssd->name.s , name.s.s, name.s.len);
... ...
@@ -293,6 +295,8 @@ int add_avp_before(avp_t *avp, avp_flags_t flags, avp_name_t name, avp_value_t v
293 295
 /* get value functions */
294 296
 inline str* get_avp_name(avp_t *avp)
295 297
 {
298
+	void** p_data; /* strict aliasing /type punning warnings workarround */
299
+	
296 300
 	switch ( avp->flags&(AVP_NAME_STR|AVP_VAL_STR) )
297 301
 	{
298 302
 		case 0:
... ...
@@ -302,10 +306,12 @@ inline str* get_avp_name(avp_t *avp)
302 306
 			return 0;
303 307
 		case AVP_NAME_STR:
304 308
 			/* avp type str, int value */
305
-			return &((struct str_int_data*)&avp->data)->name;
309
+			p_data=&avp->data;
310
+			return &((struct str_int_data*)p_data)->name;
306 311
 		case AVP_NAME_STR|AVP_VAL_STR:
307 312
 			/* avp type str, str value */
308
-			return &((struct str_str_data*)&avp->data)->name;
313
+			p_data=&avp->data;
314
+			return &((struct str_str_data*)p_data)->name;
309 315
 	}
310 316
 
311 317
 	LOG(L_ERR,"BUG:avp:get_avp_name: unknown avp type (name&val) %d\n",
... ...
@@ -316,9 +322,12 @@ inline str* get_avp_name(avp_t *avp)
316 322
 
317 323
 inline void get_avp_val(avp_t *avp, avp_value_t *val)
318 324
 {
325
+	void** p_data; /* strict aliasing /type punning warnings workarround */
326
+	
319 327
 	if (avp==0 || val==0)
320 328
 		return;
321 329
 
330
+	p_data=&avp->data;
322 331
 	switch ( avp->flags&(AVP_NAME_STR|AVP_VAL_STR) ) {
323 332
 		case 0:
324 333
 			/* avp type ID, int value */
... ...
@@ -326,15 +335,15 @@ inline void get_avp_val(avp_t *avp, avp_value_t *val)
326 335
 			break;
327 336
 		case AVP_NAME_STR:
328 337
 			/* avp type str, int value */
329
-			val->n = ((struct str_int_data*)(&avp->data))->val;
338
+			val->n = ((struct str_int_data*)p_data)->val;
330 339
 			break;
331 340
 		case AVP_VAL_STR:
332 341
 			/* avp type ID, str value */
333
-			val->s = *(str*)(&avp->data);
342
+			val->s = *(str*)(void*)(&avp->data);
334 343
 			break;
335 344
 		case AVP_NAME_STR|AVP_VAL_STR:
336 345
 			/* avp type str, str value */
337
-			val->s = (((struct str_str_data*)(&avp->data))->val);
346
+			val->s = (((struct str_str_data*)p_data)->val);
338 347
 			break;
339 348
 	}
340 349
 }