Re: [xml] Re: Access Violation



Daniel Veillard wrote:
On Mon, Jul 28, 2003 at 03:15:09PM +0100, Vincent Finn wrote:

I am using it as follows
void fn(xmlNodePtr pOperationElement)
{
    xmlNodePtr pEvent = pOperationElement->children;
    while (pEvent != NULL)
    {
            xmlNodePtr pValueText = pValue->children;
            const char* bstrValueText = reinterpret_cast<char
const*>(pValueText->content);
            // etc...
            pEvent = pEvent->next;
    }
}

I assume since it looks like heap corruption that I am misusing
the library
in some way
Is there anything here that looks wrong to anyone?


  accessing ->content without checking the type of the node first
is 100% wrong. You're making assumption which is very likely to be
false.

In my case it won't ever be false.
Unless I have misunderstood content is for getting the text from a
text
node, in which case I would have thought what I am doing is fine

I know with 100% certainty that the node I am accessing is of the
form
<E><V>48471740</V><T>01c354fc14bb8030</T></E>
so I use content to access the text values

As far as I could tell it seemed the same as using
xmlNodeListGetString() but without the need to free the xmlChar
which
seemed to be a better solution for me since I am purely reading and
want
to avoid any data copying I can

Is using content inherently unsafe?

      Vin

As Daniel mentioned, it's a little difficult making guesses with a
code snippet, but you have gotten me a little confused.  First,
could you confirm that the line

   xmlNodePtr pValueText = pValue->children;

really should be

   xmlNodePtr pValueText = pEvent->children;

or else give me a hint what pValue is pointing to.

Next, in your original mail you said the structure of your data was
  <root>
     <firstChild>
        <E>....</E>
        ...
     </firstChild>
  </root>
so I am assuming that your pOperationElement is pointing to
<firstChild>.  If that assumption is true, xmllint shows me that I
should expect a structure looking like this:-

bill billsuper work $ cat checkit.xml
<root>
    <firstChild>
        <E><V>48471740</V><T>01c354fc14bb8030</T></E>
    </firstChild>
</root>

bill billsuper work $ xmllint --debug checkit.xml
DOCUMENT
version=1.0
URL=checkit.xml
standalone=true
  ELEMENT root
    TEXT
      content=
    ELEMENT firstChild
      TEXT
        content=
      ELEMENT E
        ELEMENT V
          TEXT
            content=48471740
        ELEMENT T
          TEXT
            content=01c354fc14bb8030
      TEXT
        content=
    TEXT
      content=
bill billsuper work $

In other words, pEvent will be pointing to the TEXT node, which is
the first child of firstChild, and not to the ELEMENT E which you
expect.  This is what Daniel is talking about when he advises you to
check the node type.

If I have misunderstood, or if one of my assumptions is incorrect,
please clarify.

Regards,

Bill



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]