Browse code

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

Andrei Pelinescu-Onciul authored on 09/12/2007 13:15:24
Showing 4 changed files
... ...
@@ -78,7 +78,7 @@ MAIN_NAME=ser
78 78
 VERSION = 2
79 79
 PATCHLEVEL = 1
80 80
 SUBLEVEL =  0
81
-EXTRAVERSION = -dev14
81
+EXTRAVERSION = -dev15
82 82
 
83 83
 SER_VER = $(shell expr $(VERSION) \* 1000000 + $(PATCHLEVEL) \* 1000 + \
84 84
 			$(SUBLEVEL) )
... ...
@@ -577,7 +577,7 @@ inline static int comp_num(int op, long left, int rtype, union exp_op* r)
577 577
 		if (avp && !(avp->flags & AVP_VAL_STR)) right = val.n;
578 578
 		else return 0; /* Always fail */
579 579
 	} else if (rtype == NUMBER_ST) {
580
-		right = r->intval;
580
+		right = r->numval;
581 581
 	} else {
582 582
 		LOG(L_CRIT, "BUG: comp_num: Invalid right operand (%d)\n", rtype);
583 583
 		return E_BUG;
... ...
@@ -759,6 +759,7 @@ inline static int comp_avp(int op, avp_spec_t* spec, int rtype, union exp_op* r,
759 759
 	int_str val;
760 760
 	union exp_op num_val;
761 761
 	str tmp;
762
+	unsigned int uval;
762 763
 
763 764
 	if (spec->type & AVP_INDEX_ALL) {
764 765
 		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,
777 777
 		break;
778 778
 
779 779
 	case BINOR_OP:
780
-		return (val.n | r->intval)!=0;
780
+		return (val.n | r->numval)!=0;
781 781
 		break;
782 782
 
783 783
 	case BINAND_OP:
784
-		return (val.n & r->intval)!=0;
784
+		return (val.n & r->numval)!=0;
785 785
 		break;
786 786
 	}
787 787
 
... ...
@@ -794,18 +795,20 @@ inline static int comp_avp(int op, avp_spec_t* spec, int rtype, union exp_op* r,
794 794
 			case STRING_ST:
795 795
 				tmp.s=r->string;
796 796
 				tmp.len=strlen(r->string);
797
-				if (str2int(&tmp, (unsigned int*)&num_val.intval)<0){
797
+				if (str2int(&tmp, &uval)<0){
798 798
 					LOG(L_ERR, "ERROR: comp_avp: cannot convert string value"
799 799
 								" to int (%s)\n", ZSW(r->string));
800 800
 					return -1;
801 801
 				}
802
+				num_val.numval=uval;
802 803
 				return comp_num(op, val.n, NUMBER_ST, &num_val);
803 804
 			case STR_ST:
804
-				if (str2int(&r->str, (unsigned int*)&num_val.intval)<0){
805
+				if (str2int(&r->str, &uval)<0){
805 806
 					LOG(L_ERR, "ERROR: comp_avp: cannot convert str value"
806 807
 								" to int (%.*s)\n", r->str.len, ZSW(r->str.s));
807 808
 					return -1;
808 809
 				}
810
+				num_val.numval=uval;
809 811
 				return comp_num(op, val.n, NUMBER_ST, &num_val);
810 812
 			default:
811 813
 				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,
1064 1064
 		break;
1065 1065
 
1066 1066
 	case NUMBER_O:
1067
-		ret=!(!e->r.intval); /* !! to transform it in {0,1} */
1067
+		ret=!(!e->r.numval); /* !! to transform it in {0,1} */
1068 1068
 		break;
1069 1069
 
1070 1070
 	case ACTION_O:
... ...
@@ -218,7 +218,7 @@ void print_expr(struct expr* exp)
218 218
 					print_actions((struct action*)exp->r.param);
219 219
 					break;
220 220
 			case NUMBER_ST:
221
-					DBG("%d",exp->r.intval);
221
+					DBG("%ld",exp->r.numval);
222 222
 					break;
223 223
 			case MYSELF_ST:
224 224
 					DBG("_myself_");
... ...
@@ -101,15 +101,15 @@ enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
101 101
 
102 102
 /* Expression operand */
103 103
 union exp_op {
104
+	void* param;
105
+	long numval; /* must have the same size as a void*/
104 106
 	struct expr* expr;
105
-	struct _str str;
106 107
 	char* string;
107
-	void* param;
108
-	int intval;
109 108
 	avp_spec_t* attr;
110 109
 	select_t* select;
111 110
 	regex_t* re;
112 111
 	struct net* net;
112
+	struct _str str;
113 113
 };
114 114
 
115 115
 struct expr{