Opened 17 years ago

Closed 17 years ago

#1598 closed defect (fixed)

CPLRemoveXMLChild doesn't work (And I can't figure out how it's supposed to

Reported by: warmerdam Owned by: warmerdam
Priority: normal Milestone: 1.4.2
Component: default Version: unspecified
Severity: normal Keywords:
Cc:

Description

From Scott J Waguespack:

I had a bug in my program that I had to go through the trouble of building GDAL and Xerces to track down, and here's what I've come to:

CPLRemoveXMLChild

It's supposed to cleanly remove a child from the parent's list of children. Instead, it seems to simply set the parent's psChild to NULL. Naturally, I decided to step through the function to see what was happening.

int CPLRemoveXMLChild( CPLXMLNode *psParent, CPLXMLNode *psChild ){

CPLXMLNode *psLast = NULL, *psThis; if( psParent == NULL )

return FALSE;

for( psThis = psParent->psChild; psThis != NULL; psThis = psThis->psNext ){

if( psThis == psChild ) {

if( psLast == NULL )

psParent->psChild = psThis->psNext;

else

psLast->psNext = psThis->psNext;

psThis->psNext = NULL; return TRUE;

}

} return FALSE;

}

So, first off, it sets psLast to Null, never changes it, then uses it in an if statement. Then, the line of code which is now bound to be executed when the child is found sets psParent's child to the psChild's next sibling, eliminating all of the previous sibling that should still belong to the parent. The ultimate result is that it eliminates all siblings up until the psChild's (the psChild to be removed) next sibling.

As far as I can tell, this is what the method should be doing reliably, and it's what I've observed it doing in practice. This contradicts what it is stated to be doing in the documentation.

Change History (1)

comment:1 by warmerdam, 17 years ago

Milestone: 1.4.2
Resolution: fixed
Status: newclosed

fixed in trunk (r11362) and 1.4 branch (r11363).

Note: See TracTickets for help on using tickets.