Re: [xml] Iterating over a node set



Hi Daniel!

First of all, thanks a lot for your hint!

On Thu, 09 Jan 2003, Daniel Veillard wrote:

[...] 
  You did not indicate the way you increment or guard for xpath_items

Well, I (wrongly) had the impression that simply checking for *xpath_items
was enough since I expected xpath_items to be NULL-terminated, which it
obviously isn't.

[...] 
struct _xmlNodeSet {
    int nodeNr;                 /* number of nodes in the set */
    int nodeMax;                /* size of the array as allocated */
    xmlNodePtr *nodeTab;        /* array of nodes in no particular order */
};

What's the reason for the distinction between nodeNr and nodeMax? When I
checked their values using a debugger they contained the same values (my
node set consisted of 10 elements, indicated by both nodeNr and nodeMax).
 
You're doing illegal memory accesses by accessing after the last element.

Yes, because my condition in the while loop didn't work (node set was *not*
NULL-terminated on Solaris) and because I didn't know that I should have
rather used nodeNr in my while loop.

You're just lucky it doesn't crash on i386

Well, on my Debian 3.0 (glibc 2.2.5 based) system, the node set indeed was
NULL-terminated, so everything worked well. What I don't understand here why
is it NULL-terminated on one architecture (i386) and not on another (Sun
SPARC)?

Conclusion: I'm now aware that I simply used a data structure in the
wrong way.

Any info will be greatly appreciated!

Greetings,

        Holger



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