Skip to content

Commit

Permalink
Fix a crash when running 'snap geometries to layer'
Browse files Browse the repository at this point in the history
A crash may happen when running the alg with 'snap to anchor nodes (single layer only)' behavior.
It turns out that I made a mistake while porting the algorithm to std::sort - originally
the sorting function used -1/0/+1 for comparison, while std::sort wants '<' operator returning true/false.
Due to inconsistent results from the comparison function, std::sort would end up corrupting
the array and memory even beyond the range, causing crashes.

Related to #29400 (but does not fix it)
  • Loading branch information
wonder-sk committed Jun 7, 2019
1 parent 2a9028a commit 0ba99af
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/analysis/vector/qgsgeometrysnappersinglesource.cpp
Expand Up @@ -244,9 +244,9 @@ static bool snapLineString( QgsLineString *linestring, QgsSpatialIndex &index, Q
if ( !newVerticesAlongSegment.isEmpty() )
{
// sort by distance along the segment
std::sort( newVerticesAlongSegment.begin(), newVerticesAlongSegment.end(), []( AnchorAlongSegment p1, AnchorAlongSegment p2 )
std::sort( newVerticesAlongSegment.begin(), newVerticesAlongSegment.end(), []( const AnchorAlongSegment & p1, const AnchorAlongSegment & p2 )
{
return ( p1.along < p2.along ? -1 : ( p1.along > p2.along ) );
return p1.along < p2.along;
} );

// insert new vertices
Expand Down

0 comments on commit 0ba99af

Please sign in to comment.