0

So, I'm parsing this xml:

<layout>
    <elements>
        <first>
            <x>centered</x>
            <y>300</y>
            <text>Button</text>
            <function>toggleOption</function>
        </first>
        <second>no</second>
    </elements>

</layout>

It's being parsed by the rapidxml library. Here are the relevant lines of code:

rapidxml::xml_document<> doc;
doc.parse<0>(big_buffer);

rapidxml::xml_node<>* element_ptr = doc.first_node("layout")->first_node("elements")->first_node();

while(element_ptr){
    printf("FOUND: '%s'\n", element_ptr->name());

    element_ptr = element_ptr->next_sibling();
}

Running this causes:

FOUND: 'first'
FOUND: 'second'
*** stack smashing detected ***: ./program terminated
Aborted (core dumped)

I followed the pattern here, but the problem is element_ptr doesn't have a next_sibling(). No biggy, but the fact the element_ptr->next_sibling() causes a crash is no fun.

Community
  • 1
  • 1
  • After more investigation, I've found that the problem occurs when one sibling node, in this case "first", has any child nodes. – user3216435 Jan 07 '15 at 00:01
  • A small self-contained example is required. I use this approach regularly and have no issues. The problem is likely elsewhere... – Roddy Jan 28 '15 at 22:56

0 Answers0