From d1ab22ed926cbb979064d3580c05d511163328f8 Mon Sep 17 00:00:00 2001 From: CismonX Date: Wed, 22 Aug 2018 17:54:21 +0800 Subject: [PATCH] fix segfault --- src/collections_methods.c | 6 ++++++ tests/013-array-access.phpt | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/collections_methods.c b/src/collections_methods.c index 5d09912..5d503f2 100644 --- a/src/collections_methods.c +++ b/src/collections_methods.c @@ -311,6 +311,12 @@ void collection_offset_set(zval* object, zval* offset, zval* value) { zend_hash_update(current, Z_STR_P(offset), value); } + else + { + ERR_BAD_KEY_TYPE(); + return; + } + Z_TRY_ADDREF_P(value); } zval* collection_offset_get(zval* object, zval* offset, int type, zval* retval) diff --git a/tests/013-array-access.phpt b/tests/013-array-access.phpt index 325823d..a75367d 100644 --- a/tests/013-array-access.phpt +++ b/tests/013-array-access.phpt @@ -4,14 +4,14 @@ Test implementation of interface ArrayAccess. 'b', 'c' => 'd', 'e' => ['f' => 'g']]; $collection = Collection::init($array); -$collection['a'] = 'foo'; +$collection['a'] = 'foo'.strval(123); $collection['h'] = 'bar'; unset($collection['c']); if (empty($collection) || isset($collection['t']) || !isset($collection['e'])) echo 'Test for handlers.has_dimension failed.', PHP_EOL; if ($collection['e']['f'] != 'g') echo 'Test for handlers.read_dimension failed.', PHP_EOL; -if ($collection['a'] != 'foo' || $collection['h'] != 'bar') +if ($collection['a'] != 'foo'.strval(123) || $collection['h'] != 'bar') echo 'Test for handlers.write_dimension failed.', PHP_EOL; if (isset($collection['c'])) echo 'Test for handlers.unset_dimension failed.', PHP_EOL;