]> granicus.if.org Git - php/commitdiff
- Negative seeking is not supported
authorMarcus Boerger <helly@php.net>
Sat, 5 Mar 2005 11:35:13 +0000 (11:35 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 5 Mar 2005 11:35:13 +0000 (11:35 +0000)
ext/spl/spl_array.c
ext/spl/tests/array_014.phpt

index 20ceb691aeb32e81c0c582052029c4a320a5cf70..c35f583aecfb5eb5cea47b08a6d3ba2152a3eada 100755 (executable)
@@ -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);
index 8accd97dfc047562d46b71c700556548a694dbe0..ad9bc6c4ac26736bd5b180750294bec6793bb63f 100755 (executable)
@@ -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)