Просмотр исходного кода

Merge remote branch 'origin/andrei/pointer_alias_warnings'

compile warning fixes

* origin/andrei/pointer_alias_warnings:
  rr(s): fix recently introduced avp_cookie name bug
  core: avp aliasing warning fixes
  group: fix pointer aliasing warnings
  rr: pointer aliasing warning fixes
  db_postgres: pointer aliasing warnings fixes
  core: pointer aliasing warnings fixed
  cfg: fixed pointer aliasing warnings

Conflicts:
	cfg/cfg_ctx.h
	route.c
Andrei Pelinescu-Onciul 15 лет назад
Родитель
Сommit
6d17fe5a58
8 измененных файлов с 78 добавлено и 38 удалено
  1. 21 19
      cfg/cfg_ctx.c
  2. 13 2
      cfg/cfg_ctx.h
  3. 10 4
      modules/db_postgres/pg_fld.c
  4. 3 1
      modules_k/group/re_group.c
  5. 7 2
      modules_s/rr/avp_cookie.c
  6. 6 2
      pass_fd.c
  7. 3 3
      route.c
  8. 15 5
      usr_avp.c

+ 21 - 19
cfg/cfg_ctx.c

@@ -568,7 +568,7 @@ int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, str *var_name,
 				if (changed->group != group) continue;
 
 				memcpy(	temp_handle + changed->var->offset,
-					changed->new_val,
+					changed->new_val.vraw,
 					cfg_var_size(changed->var));
 			}
 		} else {
@@ -590,7 +590,8 @@ int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, str *var_name,
 	}
 
 	/* everything went ok, we can add the new value to the list */
-	size = sizeof(cfg_changed_var_t) + cfg_var_size(var) - 1;
+	size = sizeof(cfg_changed_var_t) -
+			sizeof(((cfg_changed_var_t*)0)->new_val) + cfg_var_size(var);
 	changed = (cfg_changed_var_t *)shm_malloc(size);
 	if (!changed) {
 		LOG(L_ERR, "ERROR: cfg_set_delayed(): not enough shm memory\n");
@@ -603,7 +604,7 @@ int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, str *var_name,
 	switch (CFG_VAR_TYPE(var)) {
 
 	case CFG_VAR_INT:
-		*(int *)changed->new_val = (int)(long)v;
+		changed->new_val.vint = (int)(long)v;
 		break;
 
 	case CFG_VAR_STRING:
@@ -611,18 +612,18 @@ int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, str *var_name,
 		s.s = v;
 		s.len = (s.s) ? strlen(s.s) : 0;
 		if (cfg_clone_str(&s, &s)) goto error;
-		*(char **)changed->new_val = s.s;
+		changed->new_val.vp = s.s;
 		break;
 
 	case CFG_VAR_STR:
 		/* clone the string to shm mem */
 		s = *(str *)v;
 		if (cfg_clone_str(&s, &s)) goto error;
-		memcpy(changed->new_val, &s, sizeof(str));
+		changed->new_val.vstr=s;
 		break;
 
 	case CFG_VAR_POINTER:
-		*(void **)changed->new_val = v;
+		changed->new_val.vp=v;
 		break;
 
 	}
@@ -799,7 +800,7 @@ int cfg_commit(cfg_ctx_t *ctx)
 		}
 
 		memcpy(	p,
-			changed->new_val,
+			changed->new_val.vraw,
 			cfg_var_size(changed->var));
 	}
 
@@ -865,8 +866,8 @@ int cfg_rollback(cfg_ctx_t *ctx)
 
 		if ((CFG_VAR_TYPE(changed->var) == CFG_VAR_STRING)
 		|| (CFG_VAR_TYPE(changed->var) == CFG_VAR_STR)) {
-			if (*(char **)(changed->new_val))
-				shm_free(*(char **)(changed->new_val));
+			if (changed->new_val.vp)
+				shm_free(changed->new_val.vp);
 		}
 		shm_free(changed);
 	}
@@ -1011,7 +1012,7 @@ int cfg_diff_next(void **h,
 			unsigned int *val_type)
 {
 	cfg_changed_var_t	*changed;
-	void	*p;
+	union cfg_var_value* pval;
 	static str	old_s, new_s;	/* we need the value even
 					after the function returns */
 
@@ -1026,29 +1027,30 @@ int cfg_diff_next(void **h,
 	/* use the module's handle to access the variable
 	It means that the variable is read from the local config
 	after forking */
-	p = *(changed->group->handle) + changed->var->offset;
+	pval = (union cfg_var_value*)
+			(*(changed->group->handle) + changed->var->offset);
 
 	switch (CFG_VAR_TYPE(changed->var)) {
 	case CFG_VAR_INT:
-		*old_val = (void *)(long)*(int *)p;
-		*new_val = (void *)(long)*(int *)changed->new_val;
+		*old_val = (void *)(long)pval->vint;
+		*new_val = (void *)(long)changed->new_val.vint;
 		break;
 
 	case CFG_VAR_STRING:
-		*old_val = (void *)*(char **)p;
-		*new_val = (void *)*(char **)changed->new_val;
+		*old_val = pval->vp;
+		*new_val = changed->new_val.vp;
 		break;
 
 	case CFG_VAR_STR:
-		memcpy(&old_s, p, sizeof(str));
+		old_s=pval->vstr;
 		*old_val = (void *)&old_s;
-		memcpy(&new_s, changed->new_val, sizeof(str));
+		new_s=changed->new_val.vstr;
 		*new_val = (void *)&new_s;
 		break;
 
 	case CFG_VAR_POINTER:
-		*old_val = *(void **)p;
-		*new_val = *(void **)changed->new_val;
+		*old_val = pval->vp;
+		*new_val = changed->new_val.vp;
 		break;
 
 	}

+ 13 - 2
cfg/cfg_ctx.h

@@ -32,14 +32,25 @@
 #include "cfg.h"
 #include "cfg_struct.h"
 
-/*! \brief linked list of variables with their new values */
+
+/* variable values */
+union cfg_var_value{
+	void* vp;
+	long vlong;
+	int vint;
+	str vstr;
+	unsigned char	vraw[1]; /* variable length */
+};
+
+
+/** linked list of variables with their new values. */
 typedef struct _cfg_changed_var {
 	cfg_group_t	*group;
 	cfg_mapping_t	*var;
 	struct _cfg_changed_var	*next;
 
 	/* blob that contains the new value */
-	unsigned char	new_val[1];
+	union cfg_var_value new_val; /* variable size */
 } cfg_changed_var_t;
 
 /*! \brief callback that is called when a new group is declared */

+ 10 - 4
modules/db_postgres/pg_fld.c

@@ -91,17 +91,23 @@ int pg_fld(db_fld_t* fld, char* table)
 }
 
 
+union ull {
+	uint64_t ui64;
+	uint32_t ui32[2];
+};
+
 static inline uint64_t htonll(uint64_t in)
 {
-	uint32_t* p = (uint32_t*)∈
-	return ((uint64_t)htonl(p[0]) << 32) + (uint64_t)htonl(p[1]);
+	union ull* p = (union ull*)&in;
+	
+	return ((uint64_t)htonl(p->ui32[0]) << 32) + (uint64_t)htonl(p->ui32[1]);
 }
 
 
 static inline uint64_t ntohll(uint64_t in)
 {
-	uint32_t* p = (uint32_t*)&in;
-	return ((uint64_t)ntohl(p[0]) << 32) + (uint64_t)ntohl(p[1]);
+	union ull* p = (union ull*)&in;
+	return ((uint64_t)ntohl(p->ui32[0]) << 32) + (uint64_t)ntohl(p->ui32[1]);
 }
 
 

+ 3 - 1
modules_k/group/re_group.c

@@ -163,6 +163,7 @@ int get_user_group(struct sip_msg *req, char *user, char *avp)
 	regmatch_t pmatch;
 	char *c;
 	int n;
+	int* pi;
 
 	if (get_username_domain( req, (group_check_p)user, &username, &domain)!=0){
 		LM_ERR("failed to get username@domain\n");
@@ -179,7 +180,8 @@ int get_user_group(struct sip_msg *req, char *user, char *avp)
 		goto error;
 	}
 
-	*(int*)uri_buf = htonl(('s'<<24) + ('i'<<16) + ('p'<<8) + ':');
+	pi=(int*)uri_buf;
+	*pi = htonl(('s'<<24) + ('i'<<16) + ('p'<<8) + ':');
 	c = uri_buf + 4;
 	memcpy( c, username.s, username.len);
 	c += username.len;

+ 7 - 2
modules_s/rr/avp_cookie.c

@@ -56,6 +56,9 @@ str *rr_get_avp_cookies(void) {
 	str *avp_name;
 	str *result = 0;
 	rr_avp_flags_t avp_flags;
+	struct str_int_data *sid;
+	struct str_str_data *ssd;
+
 
 	len = sizeof(crc);
 	for (avp_list_no=0; avp_list_no<MAX_AVP_DIALOG_LISTS; avp_list_no++) {
@@ -66,11 +69,13 @@ str *rr_get_avp_cookies(void) {
 
 			if ((avp->flags&(AVP_NAME_STR|AVP_VAL_STR)) == AVP_NAME_STR) {
 				/* avp type str, int value */
-				avp_name = &  ((struct str_int_data*)&avp->d.data[0])->name;
+				sid = (struct str_int_data*)&avp->d.data[0];
+				avp_name = &sid->name;
 			}
 			else if ((avp->flags&(AVP_NAME_STR|AVP_VAL_STR)) == (AVP_NAME_STR|AVP_VAL_STR)) {
 				/* avp type str, str value */
-				avp_name = & ((struct str_str_data*)&avp->d.data[0])->name;
+				ssd = (struct str_str_data*)&avp->d.data[0];
+				avp_name = &ssd->name;
 			}
 			else
 				avp_name = 0;  /* dummy */

+ 6 - 2
pass_fd.c

@@ -167,6 +167,7 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
 	struct iovec iov[1];
 	int ret;
 #ifdef HAVE_MSGHDR_MSG_CONTROL
+	int* pi;
 	struct cmsghdr* cmsg;
 	/* make sure msg_control will point to properly aligned data */
 	union {
@@ -183,7 +184,8 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
 	cmsg->cmsg_level = SOL_SOCKET;
 	cmsg->cmsg_type = SCM_RIGHTS;
 	cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
-	*(int*)CMSG_DATA(cmsg)=fd;
+	pi=(int*)CMSG_DATA(cmsg);
+	*pi=fd;
 	msg.msg_flags=0;
 #else
 	msg.msg_accrights=(caddr_t) &fd;
@@ -232,6 +234,7 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd, int flags)
 	int f;
 #endif /*NO_MSG_WAITALL */
 #ifdef HAVE_MSGHDR_MSG_CONTROL
+	int* pi;
 	struct cmsghdr* cmsg;
 	union{
 		struct cmsghdr cm;
@@ -315,7 +318,8 @@ poll_again:
 			ret=-1;
 			goto error;
 		}
-		*fd=*((int*) CMSG_DATA(cmsg));
+		pi=(int*) CMSG_DATA(cmsg);
+		*fd=*pi;
 	}else{
 		/*
 		LOG(L_ERR, "ERROR: receive_fd: no descriptor passed, cmsg=%p,"

+ 3 - 3
route.c

@@ -740,7 +740,7 @@ int fix_actions(struct action* a)
 						return E_UNSPEC;
 					}
 					*/
-					if ((ret=fix_rval_expr((void**)&rve))<0)
+					if ((ret=fix_rval_expr(&t->val[0].u.data))<0)
 						goto error;
 				}
 				if ( (t->val[1].type==ACTIONS_ST)&&(t->val[1].u.data) ){
@@ -820,7 +820,7 @@ int fix_actions(struct action* a)
 						ret = E_UNSPEC;
 						goto error;
 					}
-					if ((ret=fix_rval_expr((void**)&rve))<0)
+					if ((ret=fix_rval_expr(&t->val[0].u.data))<0)
 						goto error;
 				}else{
 					LOG(L_CRIT, "BUG: fix_actions: null while()"
@@ -864,7 +864,7 @@ int fix_actions(struct action* a)
 						ret = E_UNSPEC;
 						goto error;
 					}
-					if ((ret=fix_rval_expr((void**)&rve))<0)
+					if ((ret=fix_rval_expr(&t->val[0].u.data))<0)
 						goto error;
 				}else{
 					LOG(L_CRIT, "BUG: fix_actions: null drop/return"

+ 15 - 5
usr_avp.c

@@ -303,6 +303,8 @@ int add_avp_before(avp_t *avp, avp_flags_t flags, avp_name_t name, avp_value_t v
 /* get value functions */
 inline str* get_avp_name(avp_t *avp)
 {
+	struct str_int_data *sid;
+	struct str_str_data *ssd;
 	
 	switch ( avp->flags&(AVP_NAME_STR|AVP_VAL_STR) )
 	{
@@ -313,10 +315,12 @@ inline str* get_avp_name(avp_t *avp)
 			return 0;
 		case AVP_NAME_STR:
 			/* avp type str, int value */
-			return &((struct str_int_data*)&avp->d.data[0])->name;
+			sid = (struct str_int_data*)&avp->d.data[0];
+			return &sid->name;
 		case AVP_NAME_STR|AVP_VAL_STR:
 			/* avp type str, str value */
-			return &((struct str_str_data*)&avp->d.data[0])->name;
+			ssd = (struct str_str_data*)&avp->d.data[0];
+			return &ssd->name;
 	}
 
 	LOG(L_ERR,"BUG:avp:get_avp_name: unknown avp type (name&val) %d\n",
@@ -327,6 +331,9 @@ inline str* get_avp_name(avp_t *avp)
 
 inline void get_avp_val(avp_t *avp, avp_value_t *val)
 {
+	str *s;
+	struct str_int_data *sid;
+	struct str_str_data *ssd;
 	
 	if (avp==0 || val==0)
 		return;
@@ -338,15 +345,18 @@ inline void get_avp_val(avp_t *avp, avp_value_t *val)
 			break;
 		case AVP_NAME_STR:
 			/* avp type str, int value */
-			val->n = ((struct str_int_data*)&avp->d.data[0])->val;
+			sid = (struct str_int_data*)&avp->d.data[0];
+			val->n = sid->val;
 			break;
 		case AVP_VAL_STR:
 			/* avp type ID, str value */
-			val->s = *(str*)&avp->d.data[0];
+			s = (str*)&avp->d.data[0];
+			val->s = *s;
 			break;
 		case AVP_NAME_STR|AVP_VAL_STR:
 			/* avp type str, str value */
-			val->s = ((struct str_str_data*)&avp->d.data[0])->val;
+			ssd = (struct str_str_data*)&avp->d.data[0];
+			val->s = ssd->val;
 			break;
 	}
 }