1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

96 Commits

Author SHA1 Message Date
Niels Dossche
a380dcae4d Fix GH-20006: Power of 0 of BcMath number causes UB
Closes GH-20007.
2025-09-30 14:47:35 +02:00
Niels Dossche
64d511ef29 Fix GH-18641: Accessing a BcMath\Number property by ref crashes
The properties are virtual so we need a custom get_property_ptr_ptr
handler.

Closes GH-18637.
2025-05-24 20:38:33 +02:00
Saki Takamachi
4c90bb2da4 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fixed GH-17398: bcmul memory leak (#17615)
2025-01-29 19:15:10 +09:00
Saki Takamachi
5a4832f97b Fixed GH-17398: bcmul memory leak (#17615)
Changed BCG memory allocation to be forcibly released in
PHP_GSHUTDOWN_FUNCTION regardless of refcount.

Fixes #17398
Closes #17615
2025-01-29 19:12:18 +09:00
Saki Takamachi
ef036090d9 Fixed GH-17275: Fixed the calculation logic of dividend scale (#17279)
Fixes #17275
Closes #17279
2024-12-27 21:36:26 +09:00
Saki Takamachi
52ebdfbe00 Correctly round rounding mode with zero edge case (#17065)
Fixes #17064
Closes #17065
2024-12-17 00:17:23 +09:00
Saki Takamachi
b88dcc9f3e Now Number::round() does not remove trailing zeros (#17063)
Fixes #17061
Closes #17063
2024-12-07 02:00:04 +09:00
Saki Takamachi
063c3c8522 Correctly compare 0 and -0 (#17051)
Fixes #17049
Closes #17051
2024-12-07 01:52:30 +09:00
Saki Takamachi
d17ed3445d Fixed GH-16978: Avoid unnecessary padding with leading zeros (#16988)
Fixed an issue where leading zeros were padded beyond the allocated memory.

fixes #16978
closes #16988
2024-11-29 21:28:38 +09:00
Saki Takamachi
2c8662d6f9 Fixed a bug in BcMath\Number::pow() and bcpow() when raising negative powers of 0. (#16694)
Closes #16694
Fixes #16236
2024-11-20 00:16:52 +09:00
Saki Takamachi
fd1dff988e Fixed a bug where size_t underflows (#16696)
fixes #16262
closes #16696
2024-11-05 08:41:09 +09:00
Saki Takamachi
2fe7719a44 Added early return case when result is 0 (#16697)
fixes #16265
closes #16697
2024-11-05 08:38:38 +09:00
Saki Takamachi
c5b258fedc Fix GH-15968: Avoid converting objects to strings in operator calculations. (#16021) 2024-09-24 22:33:36 +09:00
Gina Peter Banyard
585cf9c156 ext/bcmath: null should not be supported for operator overloading & fix some comparison issues (#15875) 2024-09-23 11:49:33 +01:00
Saki Takamachi
f6db576c31 [RFC] ext/bcmath: Added bcdivmod (#15740)
RFC: https://wiki.php.net/rfc/add_bcdivmod_to_bcmath

Added bcdivmod() function and added divmod() method to BcMath\Number class.
2024-09-23 06:43:11 +09:00
Saki Takamachi
fad899e566 [RFC] Support object types in BCMath (#13741)
Added BcMath\Number class. It is an immutable object, has methods that are
equivalent to existing BCMath calculation functions, and can also be calculated
using operators.

The existing BCMath function returned a string for each calculation, but this
class returns an object.

RFC: https://wiki.php.net/rfc/support_object_type_in_bcmath,
https://wiki.php.net/rfc/fix_up_bcmath_number_class

---------

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2024-09-04 11:12:51 +09:00
Saki Takamachi
e8fe7e4f52 ext/bcmath: Fixed bcdiv() div by one (#15629)
Fixed the incorrect scale that should be used when dividing by 1, that is,
comparing the divisor and 1 to confirm equality.

Additionally, have increased the number of test cases for bcdiv_by_pow_10.phpt.
2024-08-30 09:33:17 +09:00
Tim Düsterhus
5905857fd2 RFC: Add the RoundingMode enum (#14833)
see https://wiki.php.net/rfc/correctly_name_the_rounding_mode_and_make_it_an_enum

Co-authored-by: Saki Takamachi <saki@php.net>
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2024-07-18 20:44:30 +02:00
Saki Takamachi
3c9ab6eb71 ext/bcmath: Moved macros and added a test 2024-07-17 21:48:16 +09:00
Gina Peter Banyard
c7bdf30daa Merge branch 'PHP-8.3'
* PHP-8.3:
  ext/bcmath: Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0)
2024-05-30 15:52:45 +01:00
Gina Peter Banyard
ba7b305530 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  ext/bcmath: Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0)
2024-05-30 15:51:05 +01:00
Gina Peter Banyard
709869c8bd ext/bcmath: Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0) 2024-05-30 15:47:25 +01:00
Saki Takamachi
8734a9a4af ext/bcmath: Prevent overflow of uint32_t/uint64_t (#14297)
If add more than a certain number of times, it will overflow, so need to adjust
the digits before adding.
2024-05-23 06:13:11 +09:00
Niels Dossche
b8abd2693e Increase test coverage of _bc_do_add() (#14131)
The final carry code was not tested.
2024-05-04 16:00:47 +02:00
Saki Takamachi
5359392717 [RFC] Add bcfloor, bcceil and bcround to BCMath (#13096)
Implementation for the "Adding bcround, bcfloor and bcceil to BCMath" RFC: https://wiki.php.net/rfc/adding_bcround_bcfloor_bcceil_to_bcmath

* Separated round mode into separate header file

Co-authored-by: Gina Peter Banyard <girgias@php.net>
2024-04-30 18:32:33 +01:00
Jorg Adam Sowa
549c657897 Fix GH-11761: Bcmath numbers with trailing zeros (#11798) 2023-07-26 13:48:50 +01:00
Jorg Adam Sowa
ee22612856 Extend tests of bcmath extension (#11563)
Add coverage for:

 * different formats of zero (0, 0.0)
 * small integers and decimals
 * large integers and large decimals with large fractional part
 * negative numbers for all of the above ones
2023-07-05 17:43:30 +01:00
Chun-Sheng, Li
f2b50156bc Add some more test cases for BCMath
Closes GH-7851.
2021-12-30 13:02:56 +01:00
Christoph M. Becker
d66854bece Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #78238: BCMath returns "-0"
2021-07-16 16:01:03 +02:00
Christoph M. Becker
9fbcaa57aa Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #78238: BCMath returns "-0"
2021-07-16 15:56:15 +02:00
Christoph M. Becker
bcb89c75ec Fix #78238: BCMath returns "-0"
There is no negative zero in the decimal system, so we must suppress
the sign.

Closes GH-7250.
2021-07-16 15:54:24 +02:00
Patrick Allaert
ac18dd0dc7 Prefer EXPECT over EXPECTF 2021-06-29 17:13:02 +02:00
Max Semenik
56f90492d6 Migrate skip checks to --EXTENSIONS--, p1
For rationale, see https://github.com/php/php-src/pull/6787

Extensions migrated in this part:
* bcmath
* bz2
* calendar
* com_dotnet
* ctype

Closes GH-6797.
2021-03-22 17:51:02 +01:00
Alex McLean
ec5e811dbd Add test cases for bcmath ValueErrors
Closes GH-6714

Signed-off-by: George Peter Banyard <girgias@php.net>
2021-03-03 18:35:15 +00:00
Jens de Nies
94a151a018 Fixed bug #80545
This converts the remaining "non well-formed" warnings in bcmath
to ValueErrors, in line with the other warning promotions that
have been performed in this extension.

Closes GH-80545.
2021-01-12 09:50:27 +01:00
Nikita Popov
3d2819e491 Fix memory leak with bcsqrt on number 0<X<1 2020-11-12 11:37:54 +01:00
Nikita Popov
ac87880add Update bcmath.scale when calling bcscale()
We should keep the value of bcmath.scale and the internal
bc_precision global synchronized.

Probably more important than the ability to retrieve bcmath.scale
via ini_get(), this also makes sure that the set scale does not
leak into the next request, as it currently does.
2020-10-21 17:06:48 +02:00
Nikita Popov
2519827732 Update gmp+bcmath parameter names
Closes GH-6205.
2020-09-29 12:34:16 +02:00
George Peter Banyard
cd05b56a6f Promote some warnings in BCMath to Errors
Also do a bit of refactoring at the same time.

Closes GH-6105
2020-09-11 17:40:06 +02:00
Máté Kocsis
7aacc705d0 Add many missing closing PHP tags to tests
Closes GH-5958
2020-08-09 22:03:36 +02:00
Vladyslav Startsev
2c97b401c6 make bcpowmod stricter by not returning false, instead throw exception
Closes GH-5747
2020-06-22 09:31:55 +02:00
Vladyslav Startsev
b64aee9706 Ensure bcmath scale is between 0 and INT_MAX
Make sure bcmatch scale is between 0 and INT_MAX, both for the
ini setting, and all the functions accepting a scale argument.
A ValueError is thrown if a function argument is out of range.

Closes GH-5455.
2020-04-27 11:53:26 +02:00
Máté Kocsis
d1764ca330 Make error messages more consistent by fixing capitalization
Closes GH-5066 As a first step, let's capitalize their initial letter when it is applicable.
2020-01-17 14:52:46 +01:00
Stanislav Malyshev
6556916759 Merge branch 'PHP-7.4'
* PHP-7.4:
  Test fixes
2019-12-16 10:31:40 -08:00
Stanislav Malyshev
d82a2f6c21 Test fixes 2019-12-16 10:31:22 -08:00
Stanislav Malyshev
0dfff646a2 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix test
  Fix bug #78793
  Fix build - no model field anymore
  Fixed bug #78910
  Fix #78878: Buffer underflow in bc_shift_addsub
  Fix test
  Fix #78862: link() silently truncates after a null byte on Windows
  Fix #78863: DirectoryIterator class silently truncates after a null byte
  Fix #78943: mail() may release string with refcount==1 twice
2019-12-16 10:07:15 -08:00
Stanislav Malyshev
d9f57e8316 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #78910
  Fix #78878: Buffer underflow in bc_shift_addsub
  Fix test
  Fix #78862: link() silently truncates after a null byte on Windows
  Fix #78863: DirectoryIterator class silently truncates after a null byte
  Fix #78943: mail() may release string with refcount==1 twice
2019-12-16 00:39:37 -08:00
Stanislav Malyshev
a65b8abf2c Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fixed bug #78910
  Fix #78878: Buffer underflow in bc_shift_addsub
  Fix test
  Fix #78862: link() silently truncates after a null byte on Windows
  Fix #78863: DirectoryIterator class silently truncates after a null byte
2019-12-16 00:38:54 -08:00
Christoph M. Becker
eb23c60087 Fix #78878: Buffer underflow in bc_shift_addsub
We must not rely on `isdigit()` to detect digits, since we only support
decimal ASCII digits in the following processing.
2019-12-16 00:05:03 -08:00
Fabien Villepinte
a555cc0b3d Clean DONE tags from tests
Remove most of the `===DONE===` tags and its variations.
Keep `===DONE===` if the test output otherwise becomes empty.

Closes GH-4872.
2019-11-07 21:31:47 +01:00