Skip to content

Commit e8a04b3

Browse files
committed
Allocate array of proper size
1 parent 412dd75 commit e8a04b3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ext/mysqlnd/mysqlnd_result.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,14 +1705,19 @@ MYSQLND_METHOD(mysqlnd_res, fetch_into)(MYSQLND_RES * result, const unsigned int
17051705
enum_mysqlnd_extension extension ZEND_FILE_LINE_DC)
17061706
{
17071707
zend_bool fetched_anything;
1708+
unsigned int array_size;
17081709

17091710
DBG_ENTER("mysqlnd_res::fetch_into");
17101711

17111712
/*
17121713
Hint Zend how many elements we will have in the hash. Thus it won't
17131714
extend and rehash the hash constantly.
17141715
*/
1715-
array_init_size(return_value, mysqlnd_num_fields(result) * 2);
1716+
array_size = result->field_count;
1717+
if ((flags & (MYSQLND_FETCH_NUM|MYSQLND_FETCH_ASSOC)) == (MYSQLND_FETCH_NUM|MYSQLND_FETCH_ASSOC)) {
1718+
array_size *= 2;
1719+
}
1720+
array_init_size(return_value, array_size);
17161721
if (FAIL == result->m.fetch_row(result, (void *)return_value, flags, &fetched_anything)) {
17171722
php_error_docref(NULL, E_WARNING, "Error while reading a row");
17181723
zend_array_destroy(Z_ARR_P(return_value));

0 commit comments

Comments
 (0)