Base_convert changes

  104618
March 10, 2019 12:29 scott@exussum.co.uk (Scott Dutton)
------CFSKIWQEPG338BOAOB0HD7JK0H6YI8
Content-Type: text/plain;
 charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi,

I have just put a pull request together to make some changes to base_conve=
rt, the changes are as follows:

1, Allow conversion of negative numbers (fixes https://bugs=2Ephp=2Enet/bu=
g=2Ephp?id=3D55393)
2, Raise a notice when passing in invalid chars as input, currently they a=
re just silently ignored

Part of the negative number change causes a BC break due to needing to use=
 a "zend_long" instead of a "zend_ulong" this breaks a number of tests, but=
 allows negative numbers to be represented correctly=2E

The PR is here https://github=2Ecom/php/php-src/pull/3911/files

I look forward to hearing thoughts on this

Thanks

Scott
------CFSKIWQEPG338BOAOB0HD7JK0H6YI8--
  104647
March 11, 2019 10:51 nikita.ppv@gmail.com (Nikita Popov)
On Sun, Mar 10, 2019 at 1:29 PM Scott Dutton <scott@exussum.co.uk> wrote:

> Hi, > > I have just put a pull request together to make some changes to > base_convert, the changes are as follows: > > 1, Allow conversion of negative numbers (fixes > https://bugs.php.net/bug.php?id=55393) > 2, Raise a notice when passing in invalid chars as input, currently they > are just silently ignored > > Part of the negative number change causes a BC break due to needing to use > a "zend_long" instead of a "zend_ulong" this breaks a number of tests, but > allows negative numbers to be represented correctly. > > The PR is here https://github.com/php/php-src/pull/3911/files > > I look forward to hearing thoughts on this > > Thanks > > Scott
Both changes sound reasonable to me. Could you show some examples where the output is going to change due to the zend_ulong->zend_long switch? Nikita
  104670
March 12, 2019 13:05 scott@exussum.co.uk (Scott Dutton)
On 11.03.2019 10:51, Nikita Popov wrote:
> > Both changes sound reasonable to me. Could you show some examples > where the > output is going to change due to the zend_ulong->zend_long switch? > > Nikita
Sure! For example var_dump(decbin(9223372036854775807)); would currently show string(64) "1000000000000000000000000000000000000000000000000000000000000000" After these changes it would show string(65) "-000000000000000000000000000000000000000000000000000000000000000" var_dump(decbin(9223372036854775806)); would be the same for both showing. string(63) "111111111111111111111111111111111111111111111111111111111111110" As the code is reused for decbin etc all of the helper functions have a similar effect. Also userland code would look like this currently $converted = base_convert($original, 2, 10); if ($original < 0) { $converted = - $converted; } So anyone who use coded around this will also break. I have pushed some fixed suggested to the PR again all comments welcome, my C is quite rusty so happy to change anything Thanks