[Openswan dev] [PATCH][Oenswan-1.X] GCC4.X compilation fixes

Vinay K Nallamothu vinay.nallamothu at gsecone.com
Sun Mar 27 19:04:16 CEST 2005


Hi,

The patch below fixes lvalue casting errors reported while compiling
with GCC4.0. Most of these changes are borrowed from 2.X which already
has these issues addressed.

There are various warnings generated during compilation mostly related
to signedness, out of range and missing prototypes. I have not addressed
these warnings although they seem to have been fixed in 2.X. I can send
patches if there is an interest.

Thanks
Vinay


 lib/pfkey_v2_build.c            |  129 +++++++++++++++++++++++++---------------
 pluto/db_ops.c                  |   27 +++++++-
 testing/utils/ikeping/ikeping.c |    2
 3 files changed, 107 insertions(+), 51 deletions(-)

==================================================================================
diff -urN openswan-1.0.9/lib/pfkey_v2_build.c openswan-1.0.9-m/lib/pfkey_v2_build.c
--- openswan-1.0.9/lib/pfkey_v2_build.c	2003-11-17 04:52:48.000000000 +0530
+++ openswan-1.0.9-m/lib/pfkey_v2_build.c	2005-03-27 17:07:35.015445728 +0530
@@ -188,9 +188,10 @@
 		SENDERR(EINVAL);
 	}
 
-	if(!(*pfkey_ext = (struct sadb_ext*)
-	     pfkey_msg = (struct sadb_msg*)
-	     MALLOC(sizeof(struct sadb_msg)))) {
+	pfkey_msg = (struct sadb_msg*)MALLOC(sizeof(struct sadb_msg));
+	*pfkey_ext = (struct sadb_ext*)pfkey_msg;
+
+	if (NULL == pfkey_msg) {
 		DEBUGGING(
 			"pfkey_msg_hdr_build: "
 			"memory allocation failed\n");
@@ -302,8 +303,8 @@
 	}
 	
 	if(!(*pfkey_ext = (struct sadb_ext*)
-	     pfkey_sa = (struct sadb_sa*)
-	     MALLOC(sizeof(struct sadb_sa)))) {
+	     (pfkey_sa = (struct sadb_sa*)
+	     MALLOC(sizeof(struct sadb_sa))))) {
 		DEBUGGING(
 			"pfkey_sa_build: "
 			"memory allocation failed\n");
@@ -356,9 +357,10 @@
 		SENDERR(EINVAL);
 	}
 
-	if(!(*pfkey_ext = (struct sadb_ext*)
-	     pfkey_lifetime = (struct sadb_lifetime*)
-	     MALLOC(sizeof(struct sadb_lifetime)))) {
+	pfkey_lifetime = (struct sadb_lifetime*)MALLOC(sizeof(struct sadb_lifetime));
+	*pfkey_ext = (struct sadb_ext*)pfkey_lifetime;
+
+	if (NULL == pfkey_lifetime) {
 		DEBUGGING(
 			"pfkey_lifetime_build: "
 			"memory allocation failed\n");
@@ -479,9 +481,11 @@
 		SENDERR(EAFNOSUPPORT); /* not supported yet */
 	}
 
-	if(!(*pfkey_ext = (struct sadb_ext*)
-	     pfkey_address = (struct sadb_address*)
-	     MALLOC(ALIGN_N(sizeof(struct sadb_address) + saddr_len, IPSEC_PFKEYv2_ALIGN) ))) {
+	pfkey_address = (struct sadb_address*)
+		MALLOC(ALIGN_N(sizeof(struct sadb_address) + saddr_len, IPSEC_PFKEYv2_ALIGN));
+	*pfkey_ext = (struct sadb_ext*)pfkey_address;
+
+	if (NULL == pfkey_address) {
 		DEBUGGING(
 			"pfkey_lifetime_build: "
 			"memory allocation failed\n");
@@ -551,10 +555,12 @@
 		SENDERR(EINVAL);
 	}
 
-	if(!(*pfkey_ext = (struct sadb_ext*)
-	     pfkey_key = (struct sadb_key*)
-	     MALLOC(sizeof(struct sadb_key) +
-				    DIVUP(key_bits, 64) * IPSEC_PFKEYv2_ALIGN))) {
+	pfkey_key = (struct sadb_key*)
+		MALLOC(sizeof(struct sadb_key) + 
+			DIVUP(key_bits, 64) * IPSEC_PFKEYv2_ALIGN);
+	*pfkey_ext = (struct sadb_ext*)pfkey_key;
+
+	if (NULL == pfkey_key) {
 		DEBUGGING(
 			"pfkey_key_build: "
 			"memory allocation failed\n");
@@ -638,9 +644,11 @@
 	}
 #endif
 	    
-	if(!(*pfkey_ext = (struct sadb_ext*)
-	     pfkey_ident = (struct sadb_ident*)
-	     MALLOC(ident_len * IPSEC_PFKEYv2_ALIGN))) {
+	pfkey_ident = (struct sadb_ident*)
+		MALLOC(ident_len * IPSEC_PFKEYv2_ALIGN);
+	*pfkey_ext = (struct sadb_ext*)pfkey_ident;
+
+	if (NULL == pfkey_ident) {
 		DEBUGGING(
 			"pfkey_ident_build: "
 			"memory allocation failed\n");
@@ -692,10 +700,12 @@
 		(*pfkey_ext)->sadb_ext_type);
 	SENDERR(EINVAL); /* don't process these yet */
 
-	if(!(*pfkey_ext = (struct sadb_ext*)
-	     pfkey_sens = (struct sadb_sens*)
-	     MALLOC(sizeof(struct sadb_sens) +
-		    (sens_len + integ_len) * sizeof(uint64_t)))) {
+	pfkey_sens = (struct sadb_sens*)
+		MALLOC(sizeof(struct sadb_sens) +
+			(sens_len + integ_len) * sizeof(uint64_t));
+	*pfkey_ext = (struct sadb_ext*)pfkey_sens;
+
+	if (NULL == pfkey_sens) {
 		DEBUGGING(
 			"pfkey_sens_build: "
 			"memory allocation failed\n");
@@ -751,10 +761,13 @@
 		SENDERR(EINVAL);
 	}
 
-	if(!(*pfkey_ext = (struct sadb_ext*)
-	     pfkey_prop = (struct sadb_prop*)
-	     MALLOC(sizeof(struct sadb_prop) +
-		    comb_num * sizeof(struct sadb_comb)))) {
+	pfkey_prop = (struct sadb_prop*)
+		MALLOC(sizeof(struct sadb_prop) +
+			comb_num * sizeof(struct sadb_comb));
+
+	*pfkey_ext = (struct sadb_ext*)pfkey_prop;
+
+	if (NULL == pfkey_prop) {
 		DEBUGGING(
 			"pfkey_prop_build: "
 			"memory allocation failed\n");
@@ -832,11 +845,13 @@
 		SENDERR(EINVAL);
 	}
 
-	if(!(*pfkey_ext = (struct sadb_ext*)
-	     pfkey_supported = (struct sadb_supported*)
-	     MALLOC(sizeof(struct sadb_supported) +
-					       alg_num *
-					       sizeof(struct sadb_alg)))) {
+	pfkey_supported = (struct sadb_supported*)
+		MALLOC(sizeof(struct sadb_supported) +
+			alg_num * sizeof(struct sadb_alg));
+
+	*pfkey_ext = (struct sadb_ext*)pfkey_supported;
+
+	if (NULL == pfkey_supported) {
 		DEBUGGING(
 			"pfkey_supported_build: "
 			"memory allocation failed\n");
@@ -913,9 +928,11 @@
 		SENDERR(EEXIST);
 	}
 	
-	if(!(*pfkey_ext = (struct sadb_ext*)
-	     pfkey_spirange = (struct sadb_spirange*)
-	     MALLOC(sizeof(struct sadb_spirange)))) {
+	pfkey_spirange = (struct sadb_spirange*)
+		MALLOC(sizeof(struct sadb_spirange));
+	*pfkey_ext = (struct sadb_ext*)pfkey_spirange;
+
+	if (NULL == pfkey_spirange) {
 		DEBUGGING(
 			"pfkey_spirange_build: "
 			"memory allocation failed\n");
@@ -957,9 +974,11 @@
 		(*pfkey_ext)->sadb_ext_type);
 	SENDERR(EINVAL); /* don't process these yet */
 
-	if(!(*pfkey_ext = (struct sadb_ext*)
-	     pfkey_x_kmprivate = (struct sadb_x_kmprivate*)
-	     MALLOC(sizeof(struct sadb_x_kmprivate)))) {
+	pfkey_x_kmprivate = (struct sadb_x_kmprivate*)
+		MALLOC(sizeof(struct sadb_x_kmprivate));
+	*pfkey_ext = (struct sadb_ext*)pfkey_x_kmprivate;
+
+	if (NULL == pfkey_x_kmprivate) {
 		DEBUGGING(
 			"pfkey_x_kmprivate_build: "
 			"memory allocation failed\n");
@@ -1011,8 +1030,12 @@
 		SENDERR(EINVAL);
 	}
 
-	if(!(*pfkey_ext = (struct sadb_ext*)pfkey_x_satype = (struct sadb_x_satype*)
-	     MALLOC(sizeof(struct sadb_x_satype)))) {
+	pfkey_x_satype = (struct sadb_x_satype*)
+	     MALLOC(sizeof(struct sadb_x_satype));
+
+	*pfkey_ext = (struct sadb_ext*)pfkey_x_satype;
+
+	if (NULL == pfkey_x_satype) {
 		DEBUGGING(
 			"pfkey_x_satype_build: "
 			"memory allocation failed\n");
@@ -1068,8 +1091,11 @@
 		"tunnel=%x netlink=%x xform=%x eroute=%x spi=%x radij=%x esp=%x ah=%x rcv=%x pfkey=%x ipcomp=%x verbose=%x?\n",
 		tunnel, netlink, xform, eroute, spi, radij, esp, ah, rcv, pfkey, ipcomp, verbose);
 
-	if(!(*pfkey_ext = (struct sadb_ext*)pfkey_x_debug = (struct sadb_x_debug*)
-	     MALLOC(sizeof(struct sadb_x_debug)))) {
+	pfkey_x_debug = (struct sadb_x_debug*)
+		MALLOC(sizeof(struct sadb_x_debug));
+	*pfkey_ext = (struct sadb_ext*)pfkey_x_debug;
+
+	if (NULL == pfkey_x_debug) {
 		DEBUGGING(
 			"pfkey_x_debug_build: "
 			"memory allocation failed\n");
@@ -1128,8 +1154,11 @@
 		"pfkey_x_nat_t_type_build: "
 		"type=%d\n", type);
 
-	if(!(*pfkey_ext = (struct sadb_ext*)pfkey_x_nat_t_type = (struct sadb_x_nat_t_type*)
-	     MALLOC(sizeof(struct sadb_x_nat_t_type)))) {
+	pfkey_x_nat_t_type = (struct sadb_x_nat_t_type*)
+		MALLOC(sizeof(struct sadb_x_nat_t_type));
+
+	*pfkey_ext = (struct sadb_ext*)pfkey_x_nat_t_type;
+	if (NULL == pfkey_x_nat_t_type) {
 		DEBUGGING(
 			"pfkey_x_nat_t_type_build: "
 			"memory allocation failed\n");
@@ -1180,8 +1209,11 @@
 		"pfkey_x_nat_t_port_build: "
 		"ext=%d, port=%d\n", exttype, port);
 
-	if(!(*pfkey_ext = (struct sadb_ext*)pfkey_x_nat_t_port = (struct sadb_x_nat_t_port*)
-	     MALLOC(sizeof(struct sadb_x_nat_t_port)))) {
+	pfkey_x_nat_t_port = (struct sadb_x_nat_t_port*)
+		MALLOC(sizeof(struct sadb_x_nat_t_port));
+	*pfkey_ext = (struct sadb_ext*)pfkey_x_nat_t_port;
+
+	if (NULL == pfkey_x_nat_t_port) {
 		DEBUGGING(
 			"pfkey_x_nat_t_port_build: "
 			"memory allocation failed\n");
@@ -1326,7 +1358,12 @@
 			memcpy(pfkey_ext,
 			       extensions[ext],
 			       (extensions[ext])->sadb_ext_len * IPSEC_PFKEYv2_ALIGN);
-			((char*)pfkey_ext) += (extensions[ext])->sadb_ext_len * IPSEC_PFKEYv2_ALIGN;
+			{      
+				char *pfkey_ext_c = (char *)pfkey_ext;
+
+				pfkey_ext_c += (extensions[ext])->sadb_ext_len * IPSEC_PFKEYv2_ALIGN;
+				pfkey_ext = (struct sadb_ext *)pfkey_ext_c;
+			}
 			/* Mark that we have seen this extension and remember the header location */
 			extensions_seen |= ( 1 << ext );
 		}
diff -urN openswan-1.0.9/pluto/db_ops.c openswan-1.0.9-m/pluto/db_ops.c
--- openswan-1.0.9/pluto/db_ops.c	2003-11-17 05:02:11.000000000 +0530
+++ openswan-1.0.9-m/pluto/db_ops.c	2005-03-27 17:25:24.111918360 +0530
@@ -200,7 +200,13 @@
 	ctx->trans0 = ctx->prop.trans = new_trans;
 	/* update trans_cur (by offset) */
 	offset = (char *)(new_trans) - (char *)(old_trans);
-	(char *)(ctx->trans_cur) += offset;
+
+	{
+	  char *cctx = (char *)(ctx->trans_cur);
+	  
+	  cctx += offset;
+	  ctx->trans_cur = (struct db_trans *)cctx;
+	}
 	/* update elem count */
 	ctx->max_trans = max_trans;
 	PFREE_ST(old_trans, db_trans_st);
@@ -232,11 +238,24 @@
 	
 	/* update attrs0 and attrs_cur (obviously) */
 	offset = (char *)(new_attrs) - (char *)(old_attrs);
-	(char *)ctx->attrs0 += offset;
-	(char *)ctx->attrs_cur += offset;
+	
+	{
+	  char *actx = (char *)(ctx->attrs0);
+	  
+	  actx += offset;
+	  ctx->attrs0 = (struct db_attr *)actx;
+	  
+	  actx = (char *)ctx->attrs_cur;
+	  actx += offset;
+	  ctx->attrs_cur = (struct db_attr *)actx;
+	}
+
 	/* for each transform, rewrite attrs pointer by offsetting it */
 	for (t=ctx->prop.trans, ti=0; ti < ctx->prop.trans_cnt; t++, ti++) {
-		(char *)(t->attrs) += offset;
+		char *actx = (char *)(t->attrs);
+ 
+		actx += offset;
+		t->attrs = (struct db_attr *)actx;
 	}
 	/* update elem count */
 	ctx->max_attrs = max_attrs;
diff -urN openswan-1.0.9/testing/utils/ikeping/ikeping.c openswan-1.0.9-m/testing/utils/ikeping/ikeping.c
--- openswan-1.0.9/testing/utils/ikeping/ikeping.c	2003-11-17 05:02:12.000000000 +0530
+++ openswan-1.0.9-m/testing/utils/ikeping/ikeping.c	2005-03-27 17:32:15.386395136 +0530
@@ -204,7 +204,7 @@
 	xchg=0;
 
 	sendlen=sizeof(sender);
-	n = recvfrom(s, &ih, sizeof(ih), 0, (struct sockaddr *)&sender, &sendlen);
+	n = recvfrom(s, &ih, sizeof(ih), 0, (struct sockaddr *)&sender, (socklen_t*)&sendlen);
 	
 	addrtot(&sender, 0, buf, sizeof(buf));
 	switch(afamily) {

==================================================================================
-- 
Views expressed in this mail are those of the individual sender and do not
bind Gsec1 Limited. or its subsidiary, unless the sender has done so expressly
with due authority of Gsec1.
_________________________________________________________________________




More information about the Dev mailing list