Browse Source

- fix for script numeric compares on 64 bit big endian systems

Andrei Pelinescu-Onciul 18 years ago
parent
commit
e922039020
4 changed files with 14 additions and 11 deletions
  1. 1 1
      Makefile.defs
  2. 9 6
      route.c
  3. 1 1
      route_struct.c
  4. 3 3
      route_struct.h

+ 1 - 1
Makefile.defs

@@ -78,7 +78,7 @@ MAIN_NAME=ser
 VERSION = 2
 PATCHLEVEL = 1
 SUBLEVEL =  0
-EXTRAVERSION = -dev14
+EXTRAVERSION = -dev15
 
 SER_VER = $(shell expr $(VERSION) \* 1000000 + $(PATCHLEVEL) \* 1000 + \
 			$(SUBLEVEL) )

+ 9 - 6
route.c

@@ -577,7 +577,7 @@ inline static int comp_num(int op, long left, int rtype, union exp_op* r)
 		if (avp && !(avp->flags & AVP_VAL_STR)) right = val.n;
 		else return 0; /* Always fail */
 	} else if (rtype == NUMBER_ST) {
-		right = r->intval;
+		right = r->numval;
 	} else {
 		LOG(L_CRIT, "BUG: comp_num: Invalid right operand (%d)\n", rtype);
 		return E_BUG;
@@ -759,6 +759,7 @@ inline static int comp_avp(int op, avp_spec_t* spec, int rtype, union exp_op* r,
 	int_str val;
 	union exp_op num_val;
 	str tmp;
+	unsigned int uval;
 
 	if (spec->type & AVP_INDEX_ALL) {
 		avp = search_first_avp(spec->type & ~AVP_INDEX_ALL, spec->name, NULL, NULL);
@@ -777,11 +778,11 @@ inline static int comp_avp(int op, avp_spec_t* spec, int rtype, union exp_op* r,
 		break;
 
 	case BINOR_OP:
-		return (val.n | r->intval)!=0;
+		return (val.n | r->numval)!=0;
 		break;
 
 	case BINAND_OP:
-		return (val.n & r->intval)!=0;
+		return (val.n & r->numval)!=0;
 		break;
 	}
 
@@ -794,18 +795,20 @@ inline static int comp_avp(int op, avp_spec_t* spec, int rtype, union exp_op* r,
 			case STRING_ST:
 				tmp.s=r->string;
 				tmp.len=strlen(r->string);
-				if (str2int(&tmp, (unsigned int*)&num_val.intval)<0){
+				if (str2int(&tmp, &uval)<0){
 					LOG(L_ERR, "ERROR: comp_avp: cannot convert string value"
 								" to int (%s)\n", ZSW(r->string));
 					return -1;
 				}
+				num_val.numval=uval;
 				return comp_num(op, val.n, NUMBER_ST, &num_val);
 			case STR_ST:
-				if (str2int(&r->str, (unsigned int*)&num_val.intval)<0){
+				if (str2int(&r->str, &uval)<0){
 					LOG(L_ERR, "ERROR: comp_avp: cannot convert str value"
 								" to int (%.*s)\n", r->str.len, ZSW(r->str.s));
 					return -1;
 				}
+				num_val.numval=uval;
 				return comp_num(op, val.n, NUMBER_ST, &num_val);
 			default:
 				LOG(L_CRIT, "BUG: comp_avp: invalid type for numeric avp "
@@ -1064,7 +1067,7 @@ inline static int eval_elem(struct run_act_ctx* h, struct expr* e,
 		break;
 
 	case NUMBER_O:
-		ret=!(!e->r.intval); /* !! to transform it in {0,1} */
+		ret=!(!e->r.numval); /* !! to transform it in {0,1} */
 		break;
 
 	case ACTION_O:

+ 1 - 1
route_struct.c

@@ -218,7 +218,7 @@ void print_expr(struct expr* exp)
 					print_actions((struct action*)exp->r.param);
 					break;
 			case NUMBER_ST:
-					DBG("%d",exp->r.intval);
+					DBG("%ld",exp->r.numval);
 					break;
 			case MYSELF_ST:
 					DBG("_myself_");

+ 3 - 3
route_struct.h

@@ -101,15 +101,15 @@ enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
 
 /* Expression operand */
 union exp_op {
+	void* param;
+	long numval; /* must have the same size as a void*/
 	struct expr* expr;
-	struct _str str;
 	char* string;
-	void* param;
-	int intval;
 	avp_spec_t* attr;
 	select_t* select;
 	regex_t* re;
 	struct net* net;
+	struct _str str;
 };
 
 struct expr{