core dump on xmlStrcmp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Johan den Boer

    #1

    core dump on xmlStrcmp


    Hi

    I tried the code below ( parseDoc ) on my xml file ( see below ) but this
    gives me a core dump on xmlStrcmp function. It seems that cur->name is a
    NULL pointer. cur->contents has the value 'story'.

    What am I doing wrong ?

    xml file

    <?xml version="1.0"?>
    <story>
    <storyinfo>
    <author>Some author</author>
    </storyinfo>
    </story>

    void parseDoc( char *docname )
    {
    xmlDocPtr doc;
    xmlNodePtr cur;

    doc = xmlParseFile(do cname);

    if (doc == NULL ) {
    fprintf(stderr, "Document not parsed successfully. \n");
    return;
    }

    cur = xmlDocGetRootEl ement(doc);

    if (cur == NULL) {
    fprintf(stderr, "empty document\n");
    xmlFreeDoc(doc) ;
    return;
    }

    // Next function call gives core dump because cur->name is NULL pointer

    if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
    fprintf(stderr, "document of the wrong type, root node != story");
    xmlFreeDoc(doc) ;
    return;
    }

    }


  • Langelage, Frank

    #2
    Re: core dump on xmlStrcmp

    Johan den Boer wrote:[color=blue]
    > Hi
    >
    > I tried the code below ( parseDoc ) on my xml file ( see below ) but this
    > gives me a core dump on xmlStrcmp function. It seems that cur->name is a
    > NULL pointer. cur->contents has the value 'story'.
    >
    > What am I doing wrong ?
    >
    > xml file
    >
    > <?xml version="1.0"?>
    > <story>
    > <storyinfo>
    > <author>Some author</author>
    > </storyinfo>
    > </story>
    >
    > void parseDoc( char *docname )
    > {
    > xmlDocPtr doc;
    > xmlNodePtr cur;
    >
    > doc = xmlParseFile(do cname);
    >
    > if (doc == NULL ) {
    > fprintf(stderr, "Document not parsed successfully. \n");
    > return;
    > }
    >
    > cur = xmlDocGetRootEl ement(doc);
    >
    > if (cur == NULL) {
    > fprintf(stderr, "empty document\n");
    > xmlFreeDoc(doc) ;
    > return;
    > }
    >
    > // Next function call gives core dump because cur->name is NULL pointer
    >
    > if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
    > fprintf(stderr, "document of the wrong type, root node != story");
    > xmlFreeDoc(doc) ;
    > return;
    > }
    >
    > }
    >
    >[/color]

    I took your code and tried this on my machine (SunBlade 150, Solaris 9,
    libxml2-2.4.23).
    Everything works like expected: name = "story" !

    Breakpoint 1, parseDoc (docname=0x10a1 0 "test.xml") at test.c:26
    26 if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
    (gdb) p *cur
    $2 = {_private = 0x0, type = XML_ELEMENT_NOD E, name = 0x20fa0 "story",
    children = 0x34a88, last = 0x34c08, parent = 0x349f0,
    next = 0x0, prev = 0x0, doc = 0x349f0, ns = 0x0, content = 0x0,
    properties = 0x0, nsDef = 0x0}
    (gdb)

    What's the version of your libxml ?

    Regards - Frank

    Comment

    • Johan den Boer

      #3
      Re: core dump on xmlStrcmp

      Sorry i linked with libxml in stead of libxml2


      "Johan den Boer" <me@knoware.n l> schreef in bericht
      news:vn88itjr3d 2727@corp.super news.com...[color=blue]
      >
      > Hi
      >
      > I tried the code below ( parseDoc ) on my xml file ( see below ) but this
      > gives me a core dump on xmlStrcmp function. It seems that cur->name is a
      > NULL pointer. cur->contents has the value 'story'.
      >
      > What am I doing wrong ?
      >
      > xml file
      >
      > <?xml version="1.0"?>
      > <story>
      > <storyinfo>
      > <author>Some author</author>
      > </storyinfo>
      > </story>
      >
      > void parseDoc( char *docname )
      > {
      > xmlDocPtr doc;
      > xmlNodePtr cur;
      >
      > doc = xmlParseFile(do cname);
      >
      > if (doc == NULL ) {
      > fprintf(stderr, "Document not parsed successfully. \n");
      > return;
      > }
      >
      > cur = xmlDocGetRootEl ement(doc);
      >
      > if (cur == NULL) {
      > fprintf(stderr, "empty document\n");
      > xmlFreeDoc(doc) ;
      > return;
      > }
      >
      > // Next function call gives core dump because cur->name is NULL[/color]
      pointer[color=blue]
      >
      > if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
      > fprintf(stderr, "document of the wrong type, root node != story");
      > xmlFreeDoc(doc) ;
      > return;
      > }
      >
      > }
      >
      >[/color]


      Comment

      Working...