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

Possible bug in flam3_interpolate() when using smooth interpolation #13

Open
mfeemster opened this issue Apr 22, 2016 · 0 comments
Open

Comments

@mfeemster
Copy link

This code in flam3_interpolate() appears to be buggy for two reasons:

       if (0 == i1) {
          fprintf(stderr, "error: cannot use smooth interpolation on first segment.\n");
          fprintf(stderr, "reverting to linear interpolation.\n");
          flam3_align(&cpi[0], &cps[i1], 2);
          smoothflag = 0;
       }

       if (ncps-1 == i2) {
          fprintf(stderr, "error: cannot use smooth interpolation on last segment.\n");
          fprintf(stderr, "reverting to linear interpolation.\n");
          flam3_align(&cpi[0], &cps[i1], 2);
          smoothflag = 0;
       }

       flam3_align(&cpi[0], &cps[i1-1], 4);
       smoothflag = 1;

If the code preceding the block shown has set i1 to 0, then it will call flam3_align() twice. Once in the first conditional, and again at the end. This could cause a crash on the second call because:

cps[i1-1]

Will be using an index of -1.

Worse, if ncps is 2 then this will call flam3_align() three times because the second block will be true, and then crash.

This will be the case when flam3_interpolate() is called from sheep_edge() since the spun array passed to it has two elements, and from flam3_cross() since the parents array also has two elements.

I believe the fix is to do the following:

if (0 == i1) 
{
          //...
}
else if (ncps-1 == i2)
{
         //...
}
else
{
       //...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant