cvs: ZendEngine2 / zend_execute.c zend_operators.c zend_operators.h zend_vm_def.h zend_vm_execute.h /tests bug46701.phpt

[email protected] ("Felipe Pena") Mon, 05 Jan 2009 19:47:13 -0000
Newsgroups php.zend-engine.cvs
Message-ID <cvsfelipe1231184833@cvsserver>
felipe		Mon Jan  5 19:47:13 2009 UTC

  Added files:                 
    /ZendEngine2/tests	bug46701.phpt 

  Modified files:              
    /ZendEngine2	zend_execute.c zend_operators.c zend_operators.h 
                	zend_vm_def.h zend_vm_execute.h 
  Log:
  - Fixed bug #46701 (Creating associative array with long values in the key fails on 32bit linux) 
  Patch by Shire
felipe-20090105194713.txt (text/plain, 14.2 KB)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_execute.c?r1=1.806&r2=1.807&diff_format=u
Index: ZendEngine2/zend_execute.c
diff -u ZendEngine2/zend_execute.c:1.806 ZendEngine2/zend_execute.c:1.807
--- ZendEngine2/zend_execute.c:1.806	Wed Dec 31 11:12:28 2008
+++ ZendEngine2/zend_execute.c	Mon Jan  5 19:47:12 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_execute.c,v 1.806 2008/12/31 11:12:28 sebastian Exp $ */
+/* $Id: zend_execute.c,v 1.807 2009/01/05 19:47:12 felipe Exp $ */
 
 #define ZEND_INTENSIVE_DEBUGGING 0
 
@@ -938,10 +938,10 @@
 				efree(offset_key.v);
 			}
 			break;
-		case IS_DOUBLE:
-			index = (long)Z_DVAL_P(dim);
+		case IS_DOUBLE: {
+			DVAL_TO_LVAL(Z_DVAL_P(dim), index);
 			goto num_index;
-
+		}
 		case IS_RESOURCE:
 			zend_error(E_STRICT, "Resource ID#%ld used as offset, casting to integer (%ld)", Z_LVAL_P(dim), Z_LVAL_P(dim));
 			/* Fall Through */
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_operators.c?r1=1.297&r2=1.298&diff_format=u
Index: ZendEngine2/zend_operators.c
diff -u ZendEngine2/zend_operators.c:1.297 ZendEngine2/zend_operators.c:1.298
--- ZendEngine2/zend_operators.c:1.297	Wed Dec 31 11:12:29 2008
+++ ZendEngine2/zend_operators.c	Mon Jan  5 19:47:12 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_operators.c,v 1.297 2008/12/31 11:12:29 sebastian Exp $ */
+/* $Id: zend_operators.c,v 1.298 2009/01/05 19:47:12 felipe Exp $ */
 
 #include <ctype.h>
 
@@ -268,42 +268,6 @@
 
 /* }}} */
 
-/* {{{ DVAL_TO_LVAL */
-#define MAX_UNSIGNED_INT ((double) LONG_MAX * 2) + 1
-#ifdef _WIN64
-# define DVAL_TO_LVAL(d, l) \
-	if ((d) > LONG_MAX) { \
-		(l) = (long)(unsigned long)(__int64) (d); \
-	} else { \
-		(l) = (long) (d); \
-	}
-#elif !defined(_WIN64) && __WORDSIZE == 64
-# define DVAL_TO_LVAL(d, l) \
-	if ((d) >= LONG_MAX) { \
-		(l) = LONG_MAX; \
-	} else if ((d) <=  LONG_MIN) { \
-		(l) = LONG_MIN; \
-	} else {\
-		(l) = (long) (d); \
-	}
-#else
-# define DVAL_TO_LVAL(d, l) \
-	if ((d) > LONG_MAX) { \
-		if ((d) > MAX_UNSIGNED_INT) { \
-			(l) = LONG_MAX; \
-		} else { \
-			(l) = (unsigned long) (d); \
-		} \
-	} else { \
-		if((d) < LONG_MIN) { \
-			(l) = LONG_MIN; \
-		} else { \
-			(l) = (long) (d); \
-		} \
-	}
-#endif
-/* }}} */
-
 /* {{{ zendi_convert_to_long */
 #define zendi_convert_to_long(op, holder, result)					\
 	if (op == result) {												\
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_operators.h?r1=1.134&r2=1.135&diff_format=u
Index: ZendEngine2/zend_operators.h
diff -u ZendEngine2/zend_operators.h:1.134 ZendEngine2/zend_operators.h:1.135
--- ZendEngine2/zend_operators.h:1.134	Wed Dec 31 11:12:29 2008
+++ ZendEngine2/zend_operators.h	Mon Jan  5 19:47:12 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_operators.h,v 1.134 2008/12/31 11:12:29 sebastian Exp $ */
+/* $Id: zend_operators.h,v 1.135 2009/01/05 19:47:12 felipe Exp $ */
 
 #ifndef ZEND_OPERATORS_H
 #define ZEND_OPERATORS_H
@@ -78,6 +78,42 @@
 ZEND_API double zend_u_strtod(const UChar *nptr, UChar **endptr);
 END_EXTERN_C()
 
+/* {{{ DVAL_TO_LVAL */
+#define MAX_UNSIGNED_INT ((double) LONG_MAX * 2) + 1
+#ifdef _WIN64
+# define DVAL_TO_LVAL(d, l) \
+       if ((d) > LONG_MAX) { \
+               (l) = (long)(unsigned long)(__int64) (d); \
+       } else { \
+               (l) = (long) (d); \
+       }
+#elif !defined(_WIN64) && __WORDSIZE == 64
+# define DVAL_TO_LVAL(d, l) \
+       if ((d) >= LONG_MAX) { \
+               (l) = LONG_MAX; \
+       } else if ((d) <=  LONG_MIN) { \
+               (l) = LONG_MIN; \
+       } else {\
+               (l) = (long) (d); \
+       }
+#else
+# define DVAL_TO_LVAL(d, l) \
+       if ((d) > LONG_MAX) { \
+               if ((d) > MAX_UNSIGNED_INT) { \
+                       (l) = LONG_MAX; \
+               } else { \
+                       (l) = (unsigned long) (d); \
+               } \
+       } else { \
+               if((d) < LONG_MIN) { \
+                       (l) = LONG_MIN; \
+               } else { \
+                       (l) = (long) (d); \
+               } \
+       }
+#endif
+/* }}} */
+
 static inline zend_uchar is_numeric_string(char *str, int length, long *lval, double *dval, int allow_errors)
 {
 	long local_lval;
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_def.h?r1=1.252&r2=1.253&diff_format=u
Index: ZendEngine2/zend_vm_def.h
diff -u ZendEngine2/zend_vm_def.h:1.252 ZendEngine2/zend_vm_def.h:1.253
--- ZendEngine2/zend_vm_def.h:1.252	Thu Jan  1 15:27:33 2009
+++ ZendEngine2/zend_vm_def.h	Mon Jan  5 19:47:12 2009
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_vm_def.h,v 1.252 2009/01/01 15:27:33 helly Exp $ */
+/* $Id: zend_vm_def.h,v 1.253 2009/01/05 19:47:12 felipe Exp $ */
 
 /* If you change this file, please regenerate the zend_vm_execute.h and
  * zend_vm_opcodes.h files by running:
@@ -3150,9 +3150,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_execute.h?r1=1.256&r2=1.257&diff_format=u
Index: ZendEngine2/zend_vm_execute.h
diff -u ZendEngine2/zend_vm_execute.h:1.256 ZendEngine2/zend_vm_execute.h:1.257
--- ZendEngine2/zend_vm_execute.h:1.256	Thu Jan  1 15:27:33 2009
+++ ZendEngine2/zend_vm_execute.h	Mon Jan  5 19:47:12 2009
@@ -2920,9 +2920,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -3453,9 +3455,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -3933,9 +3937,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -4137,9 +4143,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -4616,9 +4624,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -6285,9 +6295,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -6758,9 +6770,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -7231,9 +7245,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -7325,9 +7341,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -7795,9 +7813,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -10981,9 +11001,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -12825,9 +12847,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -14720,9 +14744,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -15671,9 +15697,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -17231,9 +17259,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -25320,9 +25350,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -27042,9 +27074,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -28814,9 +28848,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -29649,9 +29685,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:
@@ -31090,9 +31128,11 @@
 		}
 	}
 	if (offset) {
+	  	long l;
 		switch (Z_TYPE_P(offset)) {
 			case IS_DOUBLE:
-				zend_hash_index_update(Z_ARRVAL_P(array_ptr), (long) Z_DVAL_P(offset), &expr_ptr, sizeof(zval *), NULL);
+			  	DVAL_TO_LVAL(Z_DVAL_P(offset), l);
+				zend_hash_index_update(Z_ARRVAL_P(array_ptr), l, &expr_ptr, sizeof(zval *), NULL);
 				break;
 			case IS_LONG:
 			case IS_BOOL:

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug46701.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/bug46701.phpt
+++ ZendEngine2/tests/bug46701.phpt
--TEST--
Bug #46701 (Creating associative array with long values in the key fails on 32bit linux)
--SKIPIF--
<?php if (PHP_INT_MAX != 4) die('skip this test is for 32bit platforms only'); ?>
--FILE--
<?php

$test_array = array(
	0xcc5c4600 => 1,
	0xce331a00 => 2
);
$test_array[0xce359000] = 3;
  
var_dump($test_array);
var_dump($test_array[0xce331a00]);

class foo {
	public $x;
	
	public function __construct() {
		$this->x[0xce359000] = 3;
		var_dump($this->x);
	}
}

new foo;

?>
--EXPECT--
array(3) {
  [-866368000]=>
  int(1)
  [-835511808]=>
  int(2)
  [-835350528]=>
  int(3)
}
int(2)
array(1) {
  [-835350528]=>
  int(3)
}