summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2005-03-05 11:35:13 +0000
committerMarcus Boerger <helly@php.net>2005-03-05 11:35:13 +0000
commite4ce3e36efd5d2b9e9be66767db06c14d690b32a (patch)
treec87629542d3afc31bd53ddf84b4927f4ff0e471d
parent7fc626f89bb165742a7dcb660774923505fc53a0 (diff)
downloadphp-git-e4ce3e36efd5d2b9e9be66767db06c14d690b32a.tar.gz
- Negative seeking is not supported
-rwxr-xr-xext/spl/spl_array.c19
-rwxr-xr-xext/spl/tests/array_014.phpt14
2 files changed, 22 insertions, 11 deletions
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index 20ceb691ae..c35f583aec 100755
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -813,16 +813,19 @@ SPL_METHOD(Array, seek)
return;
}
- zend_hash_internal_pointer_reset_ex(aht, &intern->pos);
-
opos = position;
- while (position-- > 0 && (result = spl_array_next(intern TSRMLS_CC)) == SUCCESS);
- if (intern->pos && intern->is_ref && spl_hash_verify_pos(intern TSRMLS_CC) == FAILURE) {
- /* fail */
- } else {
- if (zend_hash_has_more_elements_ex(aht, &intern->pos) == SUCCESS) {
- return; /* ok */
+ if (position >= 0) { /* negative values are not supported */
+ zend_hash_internal_pointer_reset_ex(aht, &intern->pos);
+
+ while (position-- > 0 && (result = spl_array_next(intern TSRMLS_CC)) == SUCCESS);
+
+ if (intern->pos && intern->is_ref && spl_hash_verify_pos(intern TSRMLS_CC) == FAILURE) {
+ /* fail */
+ } else {
+ if (zend_hash_has_more_elements_ex(aht, &intern->pos) == SUCCESS) {
+ return; /* ok */
+ }
}
}
zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 TSRMLS_CC, "Seek position %ld is out of range", opos);
diff --git a/ext/spl/tests/array_014.phpt b/ext/spl/tests/array_014.phpt
index 8accd97dfc..ad9bc6c4ac 100755
--- a/ext/spl/tests/array_014.phpt
+++ b/ext/spl/tests/array_014.phpt
@@ -11,8 +11,16 @@ $it->seek(5);
var_dump($it->current());
$it->seek(4);
var_dump($it->current());
-$it->seek(-1);
-var_dump($it->current());
+try
+{
+ $it->seek(-1);
+ var_dump($it->current());
+}
+catch(Exception $e)
+{
+ echo $e->getMessage() . "\n";
+}
+
try
{
$it->seek(12);
@@ -37,7 +45,7 @@ foreach($it as $v)
int(11)
int(5)
int(4)
-int(0)
+Seek position -1 is out of range
Seek position 12 is out of range
int(0)
int(1)