Skip to content

Use single allocation for indirect values in array_multisort #11309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -5782,8 +5782,10 @@ PHP_FUNCTION(array_multisort)
* of the input arrays + 1. The last column is UNDEF to indicate the end
* of the row. It also stores the original position for stable sorting. */
indirect = (Bucket **)safe_emalloc(array_size, sizeof(Bucket *), 0);
/* Move num_array multiplication to size because it's essentially impossible to overflow. */
Bucket *indirects = (Bucket *)safe_emalloc(array_size, sizeof(Bucket) * (num_arrays + 1), 0);
for (i = 0; i < array_size; i++) {
indirect[i] = (Bucket *)safe_emalloc((num_arrays + 1), sizeof(Bucket), 0);
indirect[i] = indirects + (i * (num_arrays + 1));
}
for (i = 0; i < num_arrays; i++) {
k = 0;
Expand Down Expand Up @@ -5847,9 +5849,7 @@ PHP_FUNCTION(array_multisort)
RETVAL_TRUE;

clean_up:
for (i = 0; i < array_size; i++) {
efree(indirect[i]);
}
efree(indirects);
efree(indirect);
efree(func);
efree(arrays);
Expand Down