]> granicus.if.org Git - php/commitdiff
- Fix #32130 (ArrayIterator::seek() does not throw an Exception on invalid index)
authorMarcus Boerger <helly@php.net>
Tue, 1 Mar 2005 10:06:11 +0000 (10:06 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 1 Mar 2005 10:06:11 +0000 (10:06 +0000)
ext/spl/spl_array.c

index e19d45fadc0feb95deea3b366d615201b00dab4d..65fac7b84d742bfdf92a7d02b229796961a2c382 100755 (executable)
@@ -726,10 +726,11 @@ SPL_METHOD(Array, rewind)
  Seek to position. */
 SPL_METHOD(Array, seek)
 {
-       long position;
+       long opos, position;
        zval *object = getThis();
        spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
        HashTable *aht = HASH_OF(intern->array);
+       int result;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &position) == FAILURE) {
                return;
@@ -742,7 +743,17 @@ SPL_METHOD(Array, seek)
 
        zend_hash_internal_pointer_reset_ex(aht, &intern->pos);
        
-       while (position-- > 0 && spl_array_next(intern TSRMLS_CC) == SUCCESS);
+       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 */
+               }
+       }
+       zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 TSRMLS_CC, "Seek position %ld is out of range", opos);
 } /* }}} */
 
 int spl_array_object_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */