Menu

Crash inside TiXmlNode::LinkEndChild()

James Wang
2007-03-21
2013-05-20
  • James Wang

    James Wang - 2007-03-21

    Hi Everybody,

    Sometimes my program crashes when invoking TiXmlNode::LinkEndChild(), I don't know why the crash occurs, below is the detail about this kind of crash:

    <<source code>>
    TiXmlElement * tmpElement = new TiXmlElement("Maybe some certain identifier");
    //......
    //some code, for example, tmpElement.SetAttribute(ID, value);
    //......
    TiXmlText * cdata = new TiXmlText(sValue); //the type of sValue is 'std::string'
    cdata->SetCDATA(true);
    aElement->LinkEndChild(cdata);

    <<crash inside TiXmlNode::LinkEndChild()>>
    TiXmlNode* TiXmlNode::LinkEndChild( TiXmlNode* node )
    {
        assert( node->parent == 0 || node->parent == this );
        assert( node->GetDocument() == 0 || node->GetDocument() == this->GetDocument() );

        node->parent = this;

        node->prev = lastChild;zz
        node->next = 0;

        if ( lastChild )
            lastChild->next = node;   //******the breakpoint or crash-point is at this line******//
        else
            firstChild = node;           

        lastChild = node;
        return node;
    }

    As implied by the source code above, the lastChild of tmpElement should be NULL/0 as my program doesn't link any node(child) before the invocation of TiXmlNode::LinkEndChild(), but the fact is that the lastChild of tmpElement has been modified somewhere and it doesn't equal to NULL/0, I have spent more than three days looking for the reason, but it's just a waste of time, so do you know something about it? or do you have encoutered the same problem? any feedbacks are appreciated, thanks in advance.

    with best regards,
    James

     
    • James Wang

      James Wang - 2007-03-21

      Sorry, I forgot to tell you the details about my development environment.

      My operating system is windows xp sp2, and my IDE is MS VS2005 professional.

       
    • Ellers

      Ellers - 2007-04-02

      Hi James
      I don't know if you found your problem or not, but do you have a small, all-in-one-main() compilable version that reproduces the problem?
      Ellers
      PS
      It's probably not relevant but you use a variable called tmpElement then reference aElement?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.