summaryrefslogtreecommitdiff
path: root/Zend/zend_operators.c
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/zend_operators.c')
-rw-r--r--Zend/zend_operators.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index 8047aa6019..567d18c4aa 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -1449,6 +1449,18 @@ ZEND_API int shift_left_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /
op1_lval = Z_LVAL_P(op1);
}
+ /* prevent wrapping quirkiness on some processors where << 64 + x == << x */
+ if (Z_LVAL_P(op2) >= SIZEOF_ZEND_LONG * 8) {
+ ZVAL_LONG(result, 0);
+ return SUCCESS;
+ }
+
+ if (Z_LVAL_P(op2) < 0) {
+ zend_error(E_WARNING, "Bit shift by negative number");
+ ZVAL_FALSE(result);
+ return FAILURE;
+ }
+
ZVAL_LONG(result, op1_lval << Z_LVAL_P(op2));
return SUCCESS;
}
@@ -1469,6 +1481,18 @@ ZEND_API int shift_right_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
op1_lval = Z_LVAL_P(op1);
}
+ /* prevent wrapping quirkiness on some processors where >> 64 + x == >> x */
+ if (Z_LVAL_P(op2) >= SIZEOF_ZEND_LONG * 8) {
+ ZVAL_LONG(result, (Z_LVAL_P(op1) < 0) ? -1 : 0);
+ return SUCCESS;
+ }
+
+ if (Z_LVAL_P(op2) < 0) {
+ zend_error(E_WARNING, "Bit shift by negative number");
+ ZVAL_FALSE(result);
+ return FAILURE;
+ }
+
ZVAL_LONG(result, op1_lval >> Z_LVAL_P(op2));
return SUCCESS;
}