Skip to content

Commit

Permalink
Safety check when joining before accessing fields
Browse files Browse the repository at this point in the history
Fix #9166
  • Loading branch information
m-kuhn committed Dec 5, 2013
1 parent f2fbb2f commit f428c86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/qgsfield.h
Expand Up @@ -196,6 +196,10 @@ class CORE_EXPORT QgsFields
inline int count() const { return mFields.count(); }
//! Return number of items
inline int size() const { return mFields.count(); }
//! Return if a field index is valid
//! @param i Index of the field which needs to be checked
//! @return True if the field exists
inline bool exists( int i ) const { return i >= 0 && i < mFields.count(); }

//! Get field at particular index (must be in range 0..N-1)
inline const QgsField& operator[]( int i ) const { return mFields[i].field; }
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Expand Up @@ -351,6 +351,9 @@ void QgsVectorLayerFeatureIterator::prepareJoins()

for ( QgsAttributeList::const_iterator attIt = fetchAttributes.constBegin(); attIt != fetchAttributes.constEnd(); ++attIt )
{
if ( !fields.exists( *attIt ) )
continue;

if ( fields.fieldOrigin( *attIt ) != QgsFields::OriginJoin )
continue;

Expand Down

0 comments on commit f428c86

Please sign in to comment.