Hej !
You are correct, the proposed fix applies more down below, didn't see that
- but shouldn't it be k < 128 instead ?
> I don't agree that cvs has correct code.
> Here is all function as I have:
> I have commented line where can be done undefined memory access,
> (also I already posted possible fix).
>
> void
> lib3ds_mesh_calculate_normals(Lib3dsMesh *mesh, Lib3dsVector *normalL)
> {
> Lib3dsFaces **fl;
> Lib3dsFaces *fa;
> unsigned i,j,k;
>
> if (!mesh->faces) {
> return;
> }
>
> fl=calloc(sizeof(Lib3dsFaces*),mesh->points);
> ASSERT(fl);
> fa=calloc(sizeof(Lib3dsFaces),3*mesh->faces);
> ASSERT(fa);
> k=0;
> for (i=0; i<mesh->faces; ++i) {
> Lib3dsFace *f=&mesh->faceL[i];
> for (j=0; j<3; ++j) {
> Lib3dsFaces* l=&fa[k++];
> ASSERT(f->points[j]<mesh->points);
> l->face=f;
> l->next=fl[f->points[j]];
> fl[f->points[j]]=l;
> }
> }
>
> for (i=0; i<mesh->faces; ++i) {
> Lib3dsFace *f=&mesh->faceL[i];
> for (j=0; j<3; ++j) {
> // FIXME: static array needs at least check!!
> Lib3dsVector n,N[128];
> Lib3dsFaces *p;
> int k,l;
> int found;
>
> ASSERT(f->points[j]<mesh->points);
> //////////THIS code in you email
> if (f->smoothing) {
> lib3ds_vector_zero(n);
> k=0;
> for (p=fl[f->points[j]]; p; p=p->next) {
> found=0; // here goes zero
> for (l=0; l<k; ++l) {
> if( l >= 128 )
> printf("array N overflow: i=%d, j=%d, k=%d\n", i,j,k);
> if (fabs(lib3ds_vector_dot(N[l], p->face->normal)-1.0)<1e-5) {
> found=1; // and we get 1 !!! also l >= 128
> break;
> }
> }
> ///////////////////////END of code.
> // As you can see there is no restriction to access code bellow:
> // there is no check...
>
> // HERE is a bug.
> if (!found) { // if we have 1 ????
> if (f->smoothing & p->face->smoothing) {
> lib3ds_vector_add(n,n, p->face->normal);
> /////////////////////////////////////////////////////////////
> here sometimes i get k more than 128 and everything crashes :(
> lib3ds_vector_copy(N[k], p->face->normal);
>
> /////////////////////////////////////////////////////////////
>
>
>
> ++k;
> }
> }
> }
> }
> else {
> lib3ds_vector_copy(n, f->normal);
> }
> lib3ds_vector_normalize(n);
>
> lib3ds_vector_copy(normalL[3*i+j], n);
> }
> }
>
> free(fa);
> free(fl);
> }
>
> Gernot Ziegler:
> CVS already contains the following code, so I guess that is fixed in CVS ?
>
>
> for (i=0; i<mesh->faces; ++i) {
> Lib3dsFace *f=&mesh->faceL[i];
> for (j=0; j<3; ++j) {
> // FIXME: static array needs at least check!!
> Lib3dsVector n,N[128];
> Lib3dsFaces *p;
> int k,l;
> int found;
>
> ASSERT(f->points[j]<mesh->points);
>
> if (f->smoothing) {
> lib3ds_vector_zero(n);
> k=0;
> for (p=fl[f->points[j]]; p; p=p->next) {
> found=0;
> for (l=0; l<k; ++l) {
> if( l >= 128 )
> printf("array N overflow: i=%d, j=%d, k=%d\n", i,j,k);
> if (fabs(lib3ds_vector_dot(N[l], p->face->normal)-1.0)<1e-5) {
> found=1;
> break;
> }
> }
>
> Servus,
> Gernot
>
>
>
> -------------------------------------------------------
> All the advantages of Linux Managed Hosting--Without the Cost and Risk!
> Fully trained technicians. The highest number of Red Hat certifications in
> the hosting industry. Fanatical Support. Click to learn more
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
> _______________________________________________
> lib3ds-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/lib3ds-devel
>
Servus,
Gernot
--
T----------------------------W-E-L-C-O-M-E------------------------------T
O The Austria <=> Sweden <=> Germany <=> Netherlands connection..... H
| http://www.mpi-sb.mpg.de/~gziegler | http://www.lysator.liu.se/~gz E
\-----------------------------F-U-T-U-R-E-------------------------------/
-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
lib3ds-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lib3ds-devel