--- a/ezxml.c +++ b/ezxml.c @@ -1042,7 +1042,7 @@ ezxml_t ezxml_cut(ezxml_t xml) cur = xml->parent->child; // go back to head of subtag list if (strcmp(cur->name, xml->name)) { // not in first sibling list - while (strcmp(cur->sibling->name, xml->name)) + while (cur->sibling && strcmp(cur->sibling->name, xml->name)) cur = cur->sibling; if (cur->sibling == xml) { // first of a sibling list cur->sibling = (xml->next) ? xml->next @@ -1051,8 +1051,9 @@ ezxml_t ezxml_cut(ezxml_t xml) else cur = cur->sibling; // not first of a sibling list } - while (cur->next && cur->next != xml) cur = cur->next; - if (cur->next) cur->next = cur->next->next; // patch next list + cur = xml->parent->child; // go back to head of subtag list + while (cur && cur->next != xml) cur = cur->ordered; + if (cur && cur->next) cur->next = cur->next->next; // patch next list } } xml->ordered = xml->sibling = xml->next = NULL;