yangqiaosheng / libcitygml

Automatically exported from code.google.com/p/libcitygml
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Error in Index ca #20

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Process a geometry that need a call to Polygon::mergeRings

The method fails (stops in debug mode execution) because of accessing the 
indices array  out of its bounds.

in citymodel.cpp starting from line 244 method Polygon::mergeRings causes the 
error. It runs one time too often through the outer loop

// Create triangles' indices
int indicesSize = 3 * ( _vertices.size() - 2 );
if ( indicesSize < 3 ) return;
_indices.resize( indicesSize );
for ( int i = 0, p = 0; (i < indicesSize - 2); i++, p += 3 )
  for ( unsigned int j = 0; j < 3; j++ )
    _indices[ p + j ] = i + j;

I recommend to fix this just by also checking the limits using the p variable 
in the outer loop condition

// Create triangles' indices
int indicesSize = 3 * ( _vertices.size() - 2 );
if ( indicesSize < 3 ) return;
_indices.resize( indicesSize );
for ( int i = 0, p = 0; (p < indicesSize); i++, p += 3 )
  for ( unsigned int j = 0; j < 3; j++ )
    _indices[ p + j ] = i + j;

Kind regards,
Jan

Original issue reported on code.google.com by jan.kli...@gmail.com on 20 Jul 2011 at 12:01

GoogleCodeExporter commented 9 years ago
Thanks a lot for this report. It was a real bug which surprisingly did not 
generate a crash more often...
I have just replaced "i" by "p" in the 1st loop condition, it was certainly 
what I wanted to do initially ... I could also replace indicesSize with 
_vertices.size().

Regards,

Joachim

Original comment by jpouder...@gmail.com on 20 Jul 2011 at 1:49