Hi Robert,

On 4/20/10, Robert Osfield <[email protected]> wrote:
> I've just done a xxdiff between your and the original file and I'm
> inclined to think the original code is correct.  The code is
> dereference of a node_id which is defined by lib3ds as an unsigned
> short, so the cast is appropriate.

No, actually the first argument to compare_node_id2 is the address of
a user_id, not a node_id.  It took me a while to spot it.  You can see
this in the call to bsearch in kfdata_read:

              parent = *(Lib3dsNode**)bsearch(&p->user_id, nodes, num_nodes,
                               sizeof(Lib3dsNode*), compare_node_id2);

user_id is an unsigned int (declared in lib3ds.h), so my change to the
cast of argument a in compare_node_id2 is required: (unsigned*)a.  It
doesn't work on a big-endian system otherwise.  It's a bit unusual to
have different types for argument a & b in the comparison routine, but
is legitimate for bsearch.

> What doesn't look appropriate is that the return type is a int, while
> the parameters in lhs - rhs line are both unsigned.  Casting from
> unsigned short to int looks more appropriate

Yes, I think that's a good idea.  In fact it was the first thing I
tried when investigating the problem on Solaris.  But it doesn't
actually seemed to be required, the code works ok on both
Solaris/SPARC and Windows/Intel without it, as long as the above cast
is fixed.

Regards

Colin McDonald
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to