File tree 1 file changed +4
-4
lines changed
1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -5782,8 +5782,10 @@ PHP_FUNCTION(array_multisort)
5782
5782
* of the input arrays + 1. The last column is UNDEF to indicate the end
5783
5783
* of the row. It also stores the original position for stable sorting. */
5784
5784
indirect = (Bucket * * )safe_emalloc (array_size , sizeof (Bucket * ), 0 );
5785
+ /* Move num_arrays multiplication to size because it's essentially impossible to overflow. */
5786
+ Bucket * indirects = (Bucket * )safe_emalloc (array_size , sizeof (Bucket ) * (num_arrays + 1 ), 0 );
5785
5787
for (i = 0 ; i < array_size ; i ++ ) {
5786
- indirect [i ] = ( Bucket * ) safe_emalloc (( num_arrays + 1 ), sizeof ( Bucket ), 0 );
5788
+ indirect [i ] = indirects + ( i * ( num_arrays + 1 ));
5787
5789
}
5788
5790
for (i = 0 ; i < num_arrays ; i ++ ) {
5789
5791
k = 0 ;
@@ -5847,9 +5849,7 @@ PHP_FUNCTION(array_multisort)
5847
5849
RETVAL_TRUE ;
5848
5850
5849
5851
clean_up :
5850
- for (i = 0 ; i < array_size ; i ++ ) {
5851
- efree (indirect [i ]);
5852
- }
5852
+ efree (indirects );
5853
5853
efree (indirect );
5854
5854
efree (func );
5855
5855
efree (arrays );
You can’t perform that action at this time.
0 commit comments