Commit Graph

85 Commits

Author SHA1 Message Date
vladyslavstartsev
a07d422ade Warn about non well-formed arguments in bcmath
Co-Authored-By: Nikita Popov <nikita.ppv@googlemail.com>
Co-Authored-By: Christoph M. Becker <cmbecker69@gmx.de>
2019-05-14 15:04:21 +02:00
Peter Kokot
eb9ad31b48 [ci skip] Rename libbcmath license file to LICENSE
- More common filename accross the PHP repository
- Additionally, this patch replaces some legacy form feed (FF or ^L)
  characters (for printers) to LF (\n) newline character.
2019-05-07 01:09:25 +02:00
Peter Kokot
bb95805327 [ci skip] Fix typo 2019-04-20 22:55:37 +02:00
Peter Kokot
e8a8128665 Refactor docs files for bcmath library 2019-04-20 22:41:00 +02:00
Nikita Popov
8bb5582751 Merge branch 'PHP-7.3' into PHP-7.4 2019-03-14 17:26:17 +01:00
Nikita Popov
217c05da52 Merge branch 'PHP-7.2' into PHP-7.3 2019-03-14 17:25:54 +01:00
Nikita Popov
e7d40afb7a Fixed bug #77742
By avoiding integer overflow in the implementation entirely. The
multiplication was already explicitly checked for overflow, so also
add a check for the addition and remove the overflow checks after
the calculation.
2019-03-14 17:24:50 +01:00
Gabriel Caruso
cdd8368d6f Clean up unnecessary ternary expressions and simplify some returns
- Simplify conditions
- Use ZEND_HASH_APPLY_* instead of hard-coded booleans
- Use ZEND_NORMALIZE_BOOL
- Drop sign in favor of ZEND_NORMALIZE_BOOL
2018-12-03 01:22:14 +01:00
Peter Kokot
1ad08256f3 Sync leading and final newlines in source code files
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-14 12:56:38 +02:00
Peter Kokot
1c850bfcca Sync leading and final newlines in source code files
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-14 12:55:24 +02:00
Peter Kokot
60a69daec6 Sync leading and final newlines in source code files
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-14 12:54:08 +02:00
Peter Kokot
37c329d715 Trim trailing whitespace in source code files 2018-10-13 14:17:28 +02:00
Peter Kokot
3362620b5f Trim trailing whitespace in source code files 2018-10-13 14:16:33 +02:00
Peter Kokot
902d39a3a7 Trim trailing whitespace in source code files 2018-10-13 14:14:50 +02:00
Peter Kokot
77118fc925 Remove HAVE_ASSERT_H
The `<assert.h>` header file is part of the standard C89 headers [1] and
on older systems there needed to be also a manual check if header is
present.

Since PHP requires at least C89 manual check and the `HAVE_ASSERT_H`
symbol defined by Autoconf in configure.ac can be both removed [2].

This patch also removes unused <assert.h> includes where c files don't
use the `assert()` macro.

Refs:
[1] https://port70.net/~nsz/c/c89/c89-draft.html#4.2
[2] https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/headers.m4
2018-09-09 09:43:03 +02:00
Peter Kokot
28136b071a Remove build system files of bundled library libbcmath
The bundled library libbcmath is maintained in the php-src and its
build system files are outdated and not used.
2018-05-29 18:56:50 +02:00
Christoph M. Becker
73af7a847c Merge branch 'pull-request/2742'
* pull-request/2742:
  Fixed bug #66364 (BCMath bcmul ignores scale parameter)
2017-09-18 15:21:22 +02:00
Christoph M. Becker
18adc6f0fc Merge branch 'pull-request/2745'
* pull-request/2745:
  Fixed bug #75169 (BCMath errors/warnings bypass error handling)
2017-09-13 16:21:30 +02:00
Christoph M. Becker
0d890025ec Merge branch 'PHP-7.2'
* PHP-7.2:
  Fixed bug #46781 (BC math handles minus zero incorrectly)
2017-09-11 23:58:31 +02:00
Christoph M. Becker
77f3cef35c Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1:
  Fixed bug #46781 (BC math handles minus zero incorrectly)
2017-09-11 23:52:14 +02:00
Christoph M. Becker
87a91aef83 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Fixed bug #46781 (BC math handles minus zero incorrectly)
2017-09-11 23:46:21 +02:00
Christoph M. Becker
9aa6898b9b Fixed bug #46781 (BC math handles minus zero incorrectly)
Actually, there is no negative zero at all.  We obey Postel's law, and
still accept negative zeroes, but we store them as positive zeroes
after the conversion from string, i.e. we normalize before further
processing.
2017-09-11 23:44:23 +02:00
Christoph M. Becker
fd73a54c30 Fixed bug #75169 (BCMath errors/warnings bypass error handling)
Instead of writing warning messages to `stderr`, we employ PHP's error
handling to raise `E_WARNING` even for the single case where
`bc_rt_error()` has been called, since that did not actually error out.
We choose to call `php_error_docref()` directly in libbcmath, since
there is no upstream, and since other PHP core functionality is already
used in our bundled libbcmath. Accordingly, we remove `rt.c` so it will
not be accidentally used in the future.

Besides adapting a few existing tests, we add new tests so that the
warnings are tested at least once. We also get rid of the Windows
specific tests, since the warning behavior is now supposed to be
platform-agnostic.
2017-09-09 23:57:22 +02:00
Christoph M. Becker
d1e82b39e2 Optimize truncation to zero scale in bc_raisemod()
There's no need to use a division by one to truncate to zero scale;
instead we introduce and use `_bc_truncate()`, what is more efficient.
2017-09-09 18:41:59 +02:00
Christoph M. Becker
8826a563de Merge branch 'PHP-7.2'
* PHP-7.2:
  Fixed bug #75178 (bcpowmod() misbehaves for non-integer base or modulus)
2017-09-09 13:38:10 +02:00
Christoph M. Becker
21eab49a53 Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1:
  Fixed bug #75178 (bcpowmod() misbehaves for non-integer base or modulus)
2017-09-09 13:30:40 +02:00
Christoph M. Becker
afa39038c2 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Fixed bug #75178 (bcpowmod() misbehaves for non-integer base or modulus)
2017-09-09 13:20:14 +02:00
Christoph M. Becker
44eec946e8 Fixed bug #75178 (bcpowmod() misbehaves for non-integer base or modulus)
Since `bcpowmod()` does not support non-integral operands, we have to
truncate these in addition to emitting a respective warning. We also
have to work with the truncated values in the following.

We recognize that the division by one to enforce the truncation is
actually overkill, but we stick with it for now, and shall tackle the
issue for PHP 7.3.
2017-09-09 13:18:26 +02:00
Christoph M. Becker
870ed5106d Fixed bug #66364 (BCMath bcmul ignores scale parameter)
We change `bcmul()` and `bcpow()` so that the result has exactly the
requested scale (i.e. decimal places) to make them consistent with the
other BCMath functions.  This also changes our stance regarding bug
#52748, which had been classified as documentation problem.

We do not manipulate the numbers themselves (anymore), but rather
introduce `bc_num2str_ex()` which accepts a scale parameter that
overrides the scale of the number by omitting extraneous decimals and
adding zeros, respectively.  This also allows us to get rid of
`split_bc_num()`, which fixes bug #75164 as well.
2017-09-08 18:31:04 +02:00
Christoph M. Becker
657695fe97 Remove unused member
The `n_next` member of struct `bc_struct` is unused; the only code that
would use this member has been disabled since libbcmath has been
bundled nearly 17 years ago.  Apparently, `n_next` has been designed to
build a linked list of free numbers, but it is doubtful whether that
would be an improvement over relying on the efficiency of the ZendMM,
so we remove the remaining support altogether.

The ABI break probably affects nobody, but would be okay for a new
minor version according to our release process, anyway.
2017-09-08 16:24:38 +02:00
Christoph M. Becker
d01453b129 Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1:
  Fixed bug #54598 (bcpowmod() may return 1 if modulus is 1)
2017-09-07 00:38:59 +02:00
Christoph M. Becker
0f88a49fd5 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Fixed bug #54598 (bcpowmod() may return 1 if modulus is 1)
2017-09-07 00:32:39 +02:00
Christoph M. Becker
b2919853f8 Fixed bug #54598 (bcpowmod() may return 1 if modulus is 1)
`x mod 1` is always zero; we have to take the scale into account,
though.
2017-09-07 00:30:05 +02:00
Christoph M. Becker
5ce744091c Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1:
  Fixed bug #44995 (bcpowmod() fails if scale != 0)
2017-09-06 23:41:46 +02:00
Christoph M. Becker
d724d8c107 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Fixed bug #44995 (bcpowmod() fails if scale != 0)
2017-09-06 23:33:48 +02:00
Christoph M. Becker
dea41f3c3a Fixed bug #44995 (bcpowmod() fails if scale != 0)
`bc_divmod()` is supposed to do integer division, so we must not apply
a scale factor here.
2017-09-06 23:30:53 +02:00
Xinchen Hui
696bd37e67 Merge branch 'PHP-7.1'
* PHP-7.1:
  Fixed condition check
  Fixed condition check
  another place

Conflicts:
	ext/mcrypt/mcrypt.c
2017-04-10 14:49:13 +08:00
Xinchen Hui
65d77812fc Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Fixed condition check
2017-04-10 14:47:42 +08:00
Xinchen Hui
4bebcb84ad Fixed condition check 2017-04-10 14:47:24 +08:00
Thomas Punt
9d9defa29a Remove dead code from BCMath extension 2017-03-16 12:23:55 +01:00
Nikita Popov
edcabf6d07 Drop unnecessary allocator return value checks 2017-03-13 22:07:15 +01:00
Brian Evans
2fe9208ee3
Use modern autotools name of configure.ac instead of configure.in
configure.ac was introduced in 2001 with automake-1.15 and autoconf-2.50
to replace the file named configure.in.
Autotools is preparing to remove configure.in in Automake 2.0.
All new software should be using configure.ac.
This also fixes Bug #69770 where extensions are creating configure.in

Signed-off-by: Brian Evans <grknight@gentoo.org>
2017-01-27 06:07:40 +00:00
Remi Collet
aecd165b8f Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  use zend_error instead of zend_error_noreturn
2016-10-14 10:54:47 +02:00
Remi Collet
428ef50838 Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  use zend_error instead of zend_error_noreturn
2016-10-14 10:54:09 +02:00
Remi Collet
e1f5b6d8df use zend_error instead of zend_error_noreturn 2016-10-14 10:53:40 +02:00
Anatol Belski
a8a11b669d Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Fix bug #73190: memcpy negative parameter _bc_new_num_ex

(cherry picked from commit af1bf873fe)
2016-10-14 01:46:18 +02:00
Stanislav Malyshev
74b5662536 Fix bug #73190: memcpy negative parameter _bc_new_num_ex
(cherry picked from commit 40e7baab3c)
2016-10-12 19:48:25 +02:00
Stanislav Malyshev
40e7baab3c Fix bug #73190: memcpy negative parameter _bc_new_num_ex 2016-10-03 00:09:02 -07:00
Anatol Belski
8a8a441972 fix clang compat 2016-08-27 22:25:02 +02:00
Dmitry Stogov
4a2e40bb86 Use ZSTR_ API to access zend_string elements (this is just renaming without semantick changes). 2015-06-30 04:05:24 +03:00