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

Unitialized data is referenced in 'b2PolygonShape::Set'. #743

Closed
charlie5 opened this issue Feb 13, 2023 · 2 comments
Closed

Unitialized data is referenced in 'b2PolygonShape::Set'. #743

charlie5 opened this issue Feb 13, 2023 · 2 comments

Comments

@charlie5
Copy link

charlie5 commented Feb 13, 2023

The 'ps' array of 'b2Vec2' is not initialized and has no default constructor. This will lead to random data being fed to 'b2DistanceSquared'.

void b2PolygonShape::Set(const b2Vec2* vertices, int32 count)
    {
      b2Assert(3 <= count && count <= b2_maxPolygonVertices);
      if (count < 3)
      {
        SetAsBox(1.0f, 1.0f);
         return;
      }
   
      int32 n = b2Min(count, b2_maxPolygonVertices);
   
       // Perform welding and copy vertices into local buffer.
      b2Vec2 ps[b2_maxPolygonVertices];     // *** ps array declared here ***
      int32 tempCount = 0;
      for (int32 i = 0; i < n; ++i)
      {
         b2Vec2 v = vertices[i];
   
         bool unique = true;
         for (int32 j = 0; j < tempCount; ++j)
         {
            if (b2DistanceSquared(v, ps[j]) < ((0.5f * b2_linearSlop) * (0.5f * b2_linearSlop)))     // *** ps has not been initialized yet ***
            {
               unique = false;
               break;
            }
         }
   
         if (unique)
         {
            ps[tempCount++] = v;
         }
      }
@kritma
Copy link

kritma commented Jun 10, 2023

int32 tempCount = 0
so "for (int32 j = 0; j < tempCount; ++j)"
is skipped and ps initialized later
if (unique)
{
ps[tempCount++] = v;
}

@erincatto
Copy link
Owner

Closing out v2 issues since it is no longer supported.

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

3 participants