mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-16890: array_sum() with GMP can loose precision (LLP64)
This commit is contained in:
commit
e87a433c20
2 changed files with 16 additions and 1 deletions
|
@ -32,6 +32,10 @@
|
|||
#include "ext/random/php_random.h"
|
||||
#include "ext/random/php_random_csprng.h"
|
||||
|
||||
#ifndef mpz_fits_si_p
|
||||
# define mpz_fits_si_p mpz_fits_slong_p
|
||||
#endif
|
||||
|
||||
#define GMP_ROUND_ZERO 0
|
||||
#define GMP_ROUND_PLUSINF 1
|
||||
#define GMP_ROUND_MINUSINF 2
|
||||
|
@ -293,7 +297,7 @@ static zend_result gmp_cast_object(zend_object *readobj, zval *writeobj, int typ
|
|||
return SUCCESS;
|
||||
case _IS_NUMBER:
|
||||
gmpnum = GET_GMP_OBJECT_FROM_OBJ(readobj)->num;
|
||||
if (mpz_fits_slong_p(gmpnum)) {
|
||||
if (mpz_fits_si_p(gmpnum)) {
|
||||
ZVAL_LONG(writeobj, mpz_get_si(gmpnum));
|
||||
} else {
|
||||
ZVAL_DOUBLE(writeobj, mpz_get_d(gmpnum));
|
||||
|
|
11
ext/gmp/tests/gh16890.phpt
Normal file
11
ext/gmp/tests/gh16890.phpt
Normal file
|
@ -0,0 +1,11 @@
|
|||
--TEST--
|
||||
GH-16890 (array_sum() with GMP can loose precision (LLP64))
|
||||
--EXTENSIONS--
|
||||
gmp
|
||||
--FILE--
|
||||
<?php
|
||||
$large_int_string = (string) (PHP_INT_MAX - 1);
|
||||
var_dump(array_sum([new GMP($large_int_string), 1]) === PHP_INT_MAX);
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(true)
|
Loading…
Add table
Add a link
Reference in a new issue