Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect node tree on big-endian systems #10

Open
GoogleCodeExporter opened this issue Aug 6, 2015 · 1 comment
Open

Incorrect node tree on big-endian systems #10

GoogleCodeExporter opened this issue Aug 6, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

I found a problem on big-endian systems, e.g. Sun
SPARC/Solaris, where the node tree for hierarchical models
is not being built correctly.

The problem is in lib3ds_file.c, kfdata_read.  It passes the
address of a Lib3dsNode user_id to bsearch.  user_id is an
unsigned int.  But the bsearch comparison routine
compare_node_id2 is casting it to the address of an unsigned
short.  This will work on little-endian systems (for
user_id<65535) but doesn't work on a big-endian system.  When
the user_id value is accessed the top two (null) bytes are
being referenced.

The following simple patch fixes the problem.


$ diff -u lib3ds_file.c lib3ds_file.c.patch
--- lib3ds_file.c       Fri Apr 16 19:29:54 2010
+++ lib3ds_file.c.patch Mon Apr 19 15:18:05 2010
@@ -452,7 +452,7 @@

 static int 
 compare_node_id2( const void *a, const void *b ) {
-   return *((unsigned short*)a) - (*((Lib3dsNode**)b))->node_id;
+   return *((unsigned*)a) - (*((Lib3dsNode**)b))->node_id;
 }

Original issue reported on code.google.com by [email protected] on 19 Apr 2010 at 5:09

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant