diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-09-17 13:13:44 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-09-17 13:13:44 +0200 |
commit | d266ba4f2de013234eb70737f77d42941c0fec1e (patch) | |
tree | 6d223dba8bf56dcd7ec00ec867a85971204a4aca | |
parent | ce25fa0d245b1a5be84af8cc24790ad91286df47 (diff) | |
download | php-git-d266ba4f2de013234eb70737f77d42941c0fec1e.tar.gz |
Check for exception after calling count_values()
To avoid a duplicate error if count_values() throws.
-rw-r--r-- | Zend/zend_vm_def.h | 4 | ||||
-rw-r--r-- | Zend/zend_vm_execute.h | 12 | ||||
-rw-r--r-- | ext/ffi/tests/008.phpt | 2 | ||||
-rw-r--r-- | ext/standard/array.c | 3 |
4 files changed, 20 insertions, 1 deletions
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index c33b4f1b69..2d8fe24fbc 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -8606,6 +8606,10 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMPVAR|CV, UNUSED) if (SUCCESS == Z_OBJ_HT_P(op1)->count_elements(op1, &count)) { break; } + if (UNEXPECTED(EG(exception))) { + count = 0; + break; + } } /* if not and the object implements Countable we call its count() method */ diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index a657e02089..5927f79580 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -9634,6 +9634,10 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_ if (SUCCESS == Z_OBJ_HT_P(op1)->count_elements(op1, &count)) { break; } + if (UNEXPECTED(EG(exception))) { + count = 0; + break; + } } /* if not and the object implements Countable we call its count() method */ @@ -16771,6 +16775,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL if (SUCCESS == Z_OBJ_HT_P(op1)->count_elements(op1, &count)) { break; } + if (UNEXPECTED(EG(exception))) { + count = 0; + break; + } } /* if not and the object implements Countable we call its count() method */ @@ -46640,6 +46648,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z if (SUCCESS == Z_OBJ_HT_P(op1)->count_elements(op1, &count)) { break; } + if (UNEXPECTED(EG(exception))) { + count = 0; + break; + } } /* if not and the object implements Countable we call its count() method */ diff --git a/ext/ffi/tests/008.phpt b/ext/ffi/tests/008.phpt index 626b2890ce..fa3991abee 100644 --- a/ext/ffi/tests/008.phpt +++ b/ext/ffi/tests/008.phpt @@ -16,7 +16,7 @@ foreach ($a as $key => $val) { $a = FFI::new("struct {int x,y;}"); try { - var_dump(@count($a)); + var_dump(count($a)); } catch (Throwable $e) { echo get_class($e) . ": " . $e->getMessage()."\n"; } diff --git a/ext/standard/array.c b/ext/standard/array.c index 73b3d35a08..d44e5d50e7 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -794,6 +794,9 @@ PHP_FUNCTION(count) if (SUCCESS == Z_OBJ_HT(*array)->count_elements(array, &Z_LVAL_P(return_value))) { return; } + if (EG(exception)) { + return; + } } /* if not and the object implements Countable we call its count() method */ if (instanceof_function(Z_OBJCE_P(array), zend_ce_countable)) { |