tinyxml2 icon indicating copy to clipboard operation
tinyxml2 copied to clipboard

Improvement: Detect self reference on 'Insert...'

Open Lorandil opened this issue 3 years ago • 0 comments

Hi there,

today I managed to produce a stupid error by copy&pasting.

Here is the minimal code snipplet:

// <foo> auto *pElement = xmlDoc.NewElement("foo"); pElement->InsertEndChild( pElement ); /\ |__ this should have been some other parent element

The problems with the construct is that it compiles and appears to run fine until the xmlDoc is destroyed. Then some assertions in the clean up code are triggered. Now I could see that there was a problem, but it took me some hours to understand (and finally see) what the problem was.

I suggest to add an assertion that the pointer handed to 'InsertChildElement()' is != this What do you think?

Best regards, Sven

Lorandil avatar Jul 14 '22 16:07 Lorandil