Program: 70814
Project: 70814
Buggy source:
private void maybeGrowAdjustVertices(int cap){
  boolean vHasPositions=((vertexBufferMask & VERTEX_POSITIONS) != 0);
  boolean vHasNormals=((vertexBufferMask & VERTEX_POSITIONS) != 0);
  boolean vHasColors=((vertexBufferMask & VERTEX_POSITIONS) != 0);
  boolean vHasTexcoords=((vertexBufferMask & VERTEX_POSITIONS) != 0);
  boolean rHasPositions=hasPositions();
  boolean rHasNormals=hasNormals();
  boolean rHasColors=hasColors();
  boolean rHasTexcoords=hasTextureCoords();
  if (cap - vertexCapacity > 0) {
    cap=vertexCapacity + (vertexCapacity >> 1);
  }
  if (cap - vertexCapacity < 0) {
    cap=vertexCapacity;
  }
  int vcap=cap * vertexStride;
  if (vHasPositions != rHasPositions || vHasNormals != rHasNormals || vHasColors != rHasColors || vHasTexcoords != rHasTexcoords) {
    int newVertexStride=0;
    int newPositionOffset=-1;
    int newNormalOffset=-1;
    int newColorOffset=-1;
    int newTexcoordOffset=-1;
    byte newVertexBufferMask=0;
    if (rHasPositions) {
      newPositionOffset=newVertexStride++;
      newVertexBufferMask|=VERTEX_POSITIONS;
    }
    if (rHasNormals) {
      newNormalOffset=newVertexStride++;
      newVertexBufferMask|=VERTEX_NORMALS;
    }
    if (rHasColors) {
      newColorOffset=newVertexStride++;
      newVertexBufferMask|=VERTEX_COLORS;
    }
    if (rHasTexcoords) {
      newTexcoordOffset=newVertexStride++;
      newVertexBufferMask|=VERTEX_TEXCOORDS;
    }
    int[] newVerts=new int[cap * newVertexStride];
    Arrays.fill(newVerts,-1);
    if (vHasPositions) {
      int nidx=newPositionOffset;
      int oidx=vertexPositionOffset;
      for (int i=0; i < numVertices; ++i) {
        newVerts[nidx]=vertices[oidx];
        nidx+=newVertexStride;
        oidx+=vertexStride;
      }
    }
    if (vHasNormals) {
      int nidx=newNormalOffset;
      int oidx=vertexNormalOffset;
      for (int i=0; i < numVertices; ++i) {
        newVerts[nidx]=vertices[oidx];
        nidx+=newVertexStride;
        oidx+=vertexStride;
      }
    }
    if (vHasColors) {
      int nidx=newColorOffset;
      int oidx=vertexColorOffset;
      for (int i=0; i < numVertices; ++i) {
        newVerts[nidx]=vertices[oidx];
        nidx+=newVertexStride;
        oidx+=vertexStride;
      }
    }
    if (vHasNormals) {
      int nidx=newTexcoordOffset;
      int oidx=vertexTexcoordOffset;
      for (int i=0; i < numVertices; ++i) {
        newVerts[nidx]=vertices[oidx];
        nidx+=newVertexStride;
        oidx+=vertexStride;
      }
    }
    vertexStride=newVertexStride;
    vertexBufferMask=newVertexBufferMask;
    vertexPositionOffset=newPositionOffset;
    vertexNormalOffset=newNormalOffset;
    vertexColorOffset=newColorOffset;
    vertexTexcoordOffset=newTexcoordOffset;
    vertices=newVerts;
  }
 else   if (vcap > vertices.length) {
    vertices=Arrays.copyOf(vertices,vcap);
    int vstart=numVertices * vertexStride;
    for (int i=vstart; i < vcap; ++i) {
      vertices[i]=-1;
    }
  }
  vertexCapacity=cap;
}

Fixed version (ground truth):
private void maybeGrowAdjustVertices(int cap){
  boolean vHasPositions=((vertexBufferMask & VERTEX_POSITIONS) != 0);
  boolean vHasNormals=((vertexBufferMask & VERTEX_NORMALS) != 0);
  boolean vHasColors=((vertexBufferMask & VERTEX_COLORS) != 0);
  boolean vHasTexcoords=((vertexBufferMask & VERTEX_TEXCOORDS) != 0);
  boolean rHasPositions=hasPositions();
  boolean rHasNormals=hasNormals();
  boolean rHasColors=hasColors();
  boolean rHasTexcoords=hasTextureCoords();
  int ncap=vertexCapacity;
  if (ncap - cap < 0) {
    ncap=vertexCapacity + (vertexCapacity >> 1);
  }
  if (ncap - cap < 0) {
    ncap=cap;
  }
  int vcap=ncap * vertexStride;
  if (vHasPositions != rHasPositions || vHasNormals != rHasNormals || vHasColors != rHasColors || vHasTexcoords != rHasTexcoords) {
    int newVertexStride=0;
    int newPositionOffset=-1;
    int newNormalOffset=-1;
    int newColorOffset=-1;
    int newTexcoordOffset=-1;
    byte newVertexBufferMask=0;
    if (rHasPositions) {
      newPositionOffset=newVertexStride++;
      newVertexBufferMask|=VERTEX_POSITIONS;
    }
    if (rHasNormals) {
      newNormalOffset=newVertexStride++;
      newVertexBufferMask|=VERTEX_NORMALS;
    }
    if (rHasColors) {
      newColorOffset=newVertexStride++;
      newVertexBufferMask|=VERTEX_COLORS;
    }
    if (rHasTexcoords) {
      newTexcoordOffset=newVertexStride++;
      newVertexBufferMask|=VERTEX_TEXCOORDS;
    }
    int[] newVerts=new int[ncap * newVertexStride];
    Arrays.fill(newVerts,-1);
    if (vHasPositions) {
      int nidx=newPositionOffset;
      int oidx=vertexPositionOffset;
      for (int i=0; i < numVertices; ++i) {
        newVerts[nidx]=vertices[oidx];
        nidx+=newVertexStride;
        oidx+=vertexStride;
      }
    }
    if (vHasNormals) {
      int nidx=newNormalOffset;
      int oidx=vertexNormalOffset;
      for (int i=0; i < numVertices; ++i) {
        newVerts[nidx]=vertices[oidx];
        nidx+=newVertexStride;
        oidx+=vertexStride;
      }
    }
    if (vHasColors) {
      int nidx=newColorOffset;
      int oidx=vertexColorOffset;
      for (int i=0; i < numVertices; ++i) {
        newVerts[nidx]=vertices[oidx];
        nidx+=newVertexStride;
        oidx+=vertexStride;
      }
    }
    if (vHasNormals) {
      int nidx=newTexcoordOffset;
      int oidx=vertexTexcoordOffset;
      for (int i=0; i < numVertices; ++i) {
        newVerts[nidx]=vertices[oidx];
        nidx+=newVertexStride;
        oidx+=vertexStride;
      }
    }
    vertexStride=newVertexStride;
    vertexBufferMask=newVertexBufferMask;
    vertexPositionOffset=newPositionOffset;
    vertexNormalOffset=newNormalOffset;
    vertexColorOffset=newColorOffset;
    vertexTexcoordOffset=newTexcoordOffset;
    vertices=newVerts;
  }
 else   if (vcap > vertices.length) {
    vertices=Arrays.copyOf(vertices,vcap);
    int vstart=numVertices * vertexStride;
    for (int i=vstart; i < vcap; ++i) {
      vertices[i]=-1;
    }
  }
  vertexCapacity=cap;
}