tony2001 Sat Jun 7 21:35:53 2008 UTC
Added files:
/php-src/ext/spl/tests fastarray_015.phpt
Modified files:
/php-src/ext/spl spl_fastarray.c
Log:
more checks and tests
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_fastarray.c?r1=1.4&r2=1.5&diff_format=u
Index: php-src/ext/spl/spl_fastarray.c
diff -u php-src/ext/spl/spl_fastarray.c:1.4 php-src/ext/spl/spl_fastarray.c:1.5
--- php-src/ext/spl/spl_fastarray.c:1.4 Sat Jun 7 14:08:59 2008
+++ php-src/ext/spl/spl_fastarray.c Sat Jun 7 21:35:53 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_fastarray.c,v 1.4 2008/06/07 14:08:59 tony2001 Exp $ */
+/* $Id: spl_fastarray.c,v 1.5 2008/06/07 21:35:53 tony2001 Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -292,7 +292,7 @@
index = spl_offset_convert_to_long(offset TSRMLS_CC);
- if (index < 0 || index >= intern->array->size) {
+ if (index < 0 || intern->array == NULL || index >= intern->array->size)
{
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or
out of range", 0 TSRMLS_CC);
return NULL;
} else if(!intern->array->elements[index]) {
@@ -344,7 +344,7 @@
index = spl_offset_convert_to_long(offset TSRMLS_CC);
- if (index < 0 || index >= intern->array->size) {
+ if (index < 0 || intern->array == NULL || index >= intern->array->size)
{
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or
out of range", 0 TSRMLS_CC);
return;
} else {
@@ -382,7 +382,7 @@
index = spl_offset_convert_to_long(offset TSRMLS_CC);
- if (index < 0 || index >= intern->array->size) {
+ if (index < 0 || intern->array == NULL || index >= intern->array->size)
{
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or
out of range", 0 TSRMLS_CC);
return;
} else {
@@ -419,7 +419,7 @@
index = spl_offset_convert_to_long(offset TSRMLS_CC);
- if (index < 0 || index >= intern->array->size) {
+ if (index < 0 || intern->array == NULL || index >= intern->array->size)
{
retval = 0;
} else {
if (!intern->array->elements[index]) {
@@ -468,7 +468,11 @@
spl_fastarray_object *intern;
intern = (spl_fastarray_object *)zend_object_store_get_object(object
TSRMLS_CC);
- *count = intern->array->size;
+ if (intern->array) {
+ *count = intern->array->size;
+ } else {
+ *count = 0;
+ }
return SUCCESS;
}
@@ -515,7 +519,10 @@
}
intern = (spl_fastarray_object *)zend_object_store_get_object(object
TSRMLS_CC);
- RETURN_LONG(intern->array->size);
+ if (intern->array) {
+ RETURN_LONG(intern->array->size);
+ }
+ RETURN_LONG(0);
}
/* }}} */
@@ -531,7 +538,10 @@
}
intern = (spl_fastarray_object *)zend_object_store_get_object(object
TSRMLS_CC);
- RETURN_LONG(intern->array->size);
+ if (intern->array) {
+ RETURN_LONG(intern->array->size);
+ }
+ RETURN_LONG(0);
}
/* }}} */
@@ -553,6 +563,10 @@
}
intern = (spl_fastarray_object *)zend_object_store_get_object(object
TSRMLS_CC);
+ if (!intern->array) {
+ intern->array = ecalloc(1, sizeof(spl_fastarray));
+ }
+
spl_fastarray_resize(intern->array, size TSRMLS_CC);
RETURN_TRUE;
}
@@ -668,7 +682,7 @@
return FAILURE;
}
- if (iterator->object->current >= 0 && iterator->object->current <
iterator->object->array->size) {
+ if (iterator->object->current >= 0 && iterator->object->array &&
iterator->object->current < iterator->object->array->size) {
return SUCCESS;
}
@@ -777,7 +791,7 @@
{
spl_fastarray_object *intern =
(spl_fastarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- RETURN_BOOL(intern->current >= 0 && intern->current <
intern->array->size);
+ RETURN_BOOL(intern->current >= 0 && intern->array && intern->current <
intern->array->size);
}
/* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/fastarray_015.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/fastarray_015.phpt
+++ php-src/ext/spl/tests/fastarray_015.phpt
--TEST--
SPL: FastArray: accessing uninitialized array
--FILE--
<?php
$a = new SplFastArray('');
try {
var_dump($a[1]);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
$a[1] = 1;
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump(count($a[1]));
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump($a->getSize());
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
foreach ($a as $v) {
}
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump($a->setSize(10));
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
echo "Done\n";
?>
--EXPECTF--
Warning: SplFastArray::__construct() expects parameter 1 to be long, string
given in %s on line %d
Index invalid or out of range
Index invalid or out of range
Index invalid or out of range
int(0)
bool(true)
Done
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php