From e4ce3e36efd5d2b9e9be66767db06c14d690b32a Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sat, 5 Mar 2005 11:35:13 +0000 Subject: - Negative seeking is not supported --- ext/spl/spl_array.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'ext/spl/spl_array.c') 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); -- cgit v1.2.1