Skip to content

Fix segfault when DOMParentNode::prepend() is called when the child disappears #11906

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 3 commits into from

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Aug 7, 2023

No description provided.

@nielsdos
Copy link
Member Author

nielsdos commented Aug 7, 2023

omg, there's still an issue here even after this fix 😞
We also have to update the last pointer of the parent if there are no children.
We should just use dom_pre_insert here and be done with it, that function will take care of this mess. And if we're lucky, the compiler can optimize away some redundant checks by inlining.

@nielsdos
Copy link
Member Author

nielsdos commented Aug 7, 2023

Pushed the change, I'll check and test out append() tomorrow

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

I'm trusting that the output is correct, even if I cannot make out the different echos.

The actual code change is very intuitive and straight forward.

Comment on lines +18 to +25
$test = $doc->createElement('foo');
$test->append($child);
echo $doc->saveXML();
echo $doc->saveXML($test), "\n";
$test->prepend($child);
echo $doc->saveXML();
echo $doc->saveXML($test), "\n";
$test->append($child);
Copy link
Member

Choose a reason for hiding this comment

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

I can't make out where the output of one echo ends and where another echo starts.

Maybe add some ``echo "----------\n";` to make it more obvious?

Copy link
Member Author

Choose a reason for hiding this comment

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

@nielsdos nielsdos closed this in d19e4da Aug 8, 2023
jorgsowa pushed a commit to jorgsowa/php-src that referenced this pull request Aug 16, 2023
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.

2 participants