Skip to content

Conversation

@lt
Copy link
Contributor

@lt lt commented Oct 31, 2016

https://bugs.php.net/bug.php?id=73374

strtoll doesn't detect 0b as a prefix so we have to fake it.

@lt
Copy link
Contributor Author

lt commented Oct 31, 2016

I don't really feel very happy about the code for sending the negative value to ZEND_STRTOL but I'm not sure how to improve it. Advice welcome.

@lt
Copy link
Contributor Author

lt commented Nov 3, 2016

Made the prefix check a little less terrible, I think.

@lt
Copy link
Contributor Author

lt commented Nov 3, 2016

Uff, looks like strtoll allows an arbitrary amount of whitespace before the numeric string. I'll cater for this later.

@hikari-no-yume
Copy link
Contributor

When you do, be sure to check whitespace in the same manner it does. I think it uses the same rules as isspace(), but I'm not sure.

@krakjoe
Copy link
Member

krakjoe commented Jan 1, 2017

@lt bump ...

@lt
Copy link
Contributor Author

lt commented Jan 9, 2017

@krakjoe I've added the whitespace checks, and a check for a unary '+' symbol.

zval *num;
zend_long base = 10;

zend_long strlen;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be size_t


if (tmpval[0] == '0' && tmpval[1] == 'b') {
/* This effectively causes the string to have two leading zeros */
tmpval[1] = '0';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately doing this is not possible, as it may cause SHM corruption.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that sucks, I was trying to avoid copying the string.

tmpval++;
}

if (tmpval[0] == '0' && tmpval[1] == 'b') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we accept 0X next to 0x in intval? If so, 0B should be supported here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick test shows 0X is accepted.

//TODO

lt added 3 commits January 9, 2017 14:11
Nikita informs me that the previous code could
cause potential SHM corruption.
offset = 1;
}

if (strval[offset] == '0' && (strval[offset + 1] == 'b' || strval[offset + 1] == 'B')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're missing a base==0 check somewhere around here.

--EXPECTF--
--- Good Inputs ---
string(34) "0b11111111111111111111111111111111"
int(4294967295)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is presumably going to have different output on 32 bit and 64 bit. We either need to fork the test or, more easily, drop one bit :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop 32-bit support \o/

@nikic nikic self-assigned this Jan 10, 2017
@nikic
Copy link
Member

nikic commented Jan 11, 2017

@krakjoe This fine for 7.1?

@krakjoe
Copy link
Member

krakjoe commented Jan 11, 2017

👍

@nikic
Copy link
Member

nikic commented Jan 12, 2017

Merged via 4f7b498, thanks!

@nikic nikic closed this Jan 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants