diff options
author | Andrea Faulds <ajf@ajf.me> | 2014-08-16 00:54:37 +0100 |
---|---|---|
committer | Andrea Faulds <ajf@ajf.me> | 2014-08-19 20:21:23 +0100 |
commit | 38bc0a05c0bcf6008347c2297ce1f0a5607409d5 (patch) | |
tree | 034f5411413697d85bdce1ae5ef5d331490b95ea | |
parent | 2f5e508e39567ca577de34b8c6005e49ac1ee93c (diff) | |
download | php-git-38bc0a05c0bcf6008347c2297ce1f0a5607409d5.tar.gz |
Prevent bit shift count wrapping quirkiness on some CPUs for right shift
-rw-r--r-- | Zend/zend_operators.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 7d591f52ef..98210953a0 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -1519,6 +1519,12 @@ 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_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); |