Skip to content

Fix bug 71572 #1761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Fix bug 71572 #1761

wants to merge 1 commit into from

Conversation

flaupretre
Copy link
Contributor

@@ -1327,6 +1327,8 @@ static zend_never_inline void zend_binary_assign_op_obj_dim(zval *object, zval *
static void zend_assign_to_string_offset(zval *str, zend_long offset, zval *value, zval *result)
{
zend_string *old_str;
char ch;
zend_long string_len;
Copy link
Member

Choose a reason for hiding this comment

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

Should be size_t.

@flaupretre
Copy link
Contributor Author

@nikic When using an invalid string offset, the assignment returns null. I did the same for assignment from an empty string. A quick look at zend_execute.c shows that some other failing assignments also return null. But, returning the unchanged character is an option too. As you know the core much better than me, just tell me which one you prefer.

Edit: after thinking more about it, I now also think that returning the unchanged character is more consistent. Patch modified.

@nikic
Copy link
Member

nikic commented Feb 12, 2016

@flaupretre As all the other dimension assignment failure cases return null, this looks fine.


$str = "abc";
var_dump($str{0} = "");
var_dump($str);
Copy link
Member

Choose a reason for hiding this comment

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

Please add a test case for $str{10} = "" as well. Currently this will still extend the string, and likely additionally leave one uninitialized byte.

@flaupretre
Copy link
Contributor Author

@nikic So, finally, as both are possible (and I don't have a strong opinion about it), which one is better, in your opinion ?

@nikic
Copy link
Member

nikic commented Feb 12, 2016

Just thinking out loud. The options are:

  • Return the original RHS. This would be, for a number of reasons, the most useful and sane thing to do, but sadly it's just not the way other assignments work.
  • Return the result of interpreting the LHS as a read operation. This would mean returning the original character if the offset is within range or the empty string if the offset is larger than the string length. However, this does not match the null return value when assigning to a negative string offset (it ought to be an empty string instead, if this pattern were followed).
  • Return null, following the other non-fatal dimension assignment error cases.
  • A mix of these, returning the original LHS character if within range, null otherwise.
  • Throw an exception :P

I'd probably go for always returning null.

@flaupretre
Copy link
Contributor Author

New version. If RHS resolves to an empty string :

  • LHS string is never modified (no extension if offset larger than string length)
  • assignment returns null.


if (offset < 0) {
if (offset < 0) { /* Error on negative offset */
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this meant to be a new line? Using a tab here is strange.

@hikari-no-yume
Copy link
Contributor

This looks good to me, any objections to merging?

@nikic
Copy link
Member

nikic commented Feb 14, 2016

Merged via be607e7. Per Andreas suggestion, I've moved the new comments to the next line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants