]> granicus.if.org Git - php/commitdiff
- Fixed endless loop and segfault
authorFelipe Pena <felipe@php.net>
Fri, 12 Sep 2008 17:30:53 +0000 (17:30 +0000)
committerFelipe Pena <felipe@php.net>
Fri, 12 Sep 2008 17:30:53 +0000 (17:30 +0000)
ext/unicode/tests/textiterator_getall_001.phpt [new file with mode: 0644]
ext/unicode/tests/textiterator_next_001.phpt [new file with mode: 0644]
ext/unicode/unicode_iterators.c

diff --git a/ext/unicode/tests/textiterator_getall_001.phpt b/ext/unicode/tests/textiterator_getall_001.phpt
new file mode 100644 (file)
index 0000000..e819388
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+TextIterator::getAll(): Simple test
+--FILE--
+<?php
+
+$x = new textiterator('asda');
+var_dump($x->getAll());
+
+?>
+--EXPECT--
+array(4) {
+  [0]=>
+  unicode(1) "a"
+  [1]=>
+  unicode(1) "s"
+  [2]=>
+  unicode(1) "d"
+  [3]=>
+  unicode(1) "a"
+}
diff --git a/ext/unicode/tests/textiterator_next_001.phpt b/ext/unicode/tests/textiterator_next_001.phpt
new file mode 100644 (file)
index 0000000..2d2200f
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+TextIterator::next(): Testing with no data
+--FILE--
+<?php
+
+$x = new textiterator;
+var_dump($x->next());
+
+?>
+--EXPECTF--
+Warning: TextIterator::__construct() expects at least 1 parameter, 0 given in %s on line %d
+int(-1)
index a3e66a3f5864e46c2f2300c523a34369bd880fb1..61a381b6baccad05077102e9096a15511e4e6a47 100644 (file)
@@ -157,6 +157,11 @@ static void text_iter_cp_next(text_iter_obj* object, long flags TSRMLS_DC)
        if (object->u.cp.offset == UBRK_DONE) {
                return;
        }
+       
+       if (object->text == NULL) {
+               object->u.cp.offset = object->u.cp.cp_offset = UBRK_DONE;
+               return;
+       }
 
        if (flags & ITER_REVERSE) {
                U16_BACK_1(object->text, 0, object->u.cp.offset);