Skip to content

Commit ecbe0e4

Browse files
committed
validate attribute index in editor widget calls
1 parent d0bd9a2 commit ecbe0e4

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/app/pluginmanager/qgspluginitemdelegate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void QgsPluginItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem
6969
if ( !iconPixmap.isNull() )
7070
{
7171
int iconSize = pixelsHigh;
72-
painter->drawPixmap( option.rect.left() + 1.2 * pixelsHigh , option.rect.top() + 0.2 * pixelsHigh, iconSize, iconSize, iconPixmap );
72+
painter->drawPixmap( option.rect.left() + 1.2 * pixelsHigh, option.rect.top() + 0.2 * pixelsHigh, iconSize, iconSize, iconPixmap );
7373
}
7474

7575
// Draw the text

src/core/qgsvectorlayer.cpp

+21-6
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,9 @@ const QString QgsVectorLayer::editorWidgetV2( const QString& fieldName ) const
21242124

21252125
const QgsEditorWidgetConfig QgsVectorLayer::editorWidgetV2Config( int fieldIdx ) const
21262126
{
2127+
if ( fieldIdx < 0 || fieldIdx >= mUpdatedFields.count() )
2128+
return QgsEditorWidgetConfig();
2129+
21272130
return mEditorWidgetV2Configs.value( mUpdatedFields[fieldIdx].name() );
21282131
}
21292132

@@ -2182,7 +2185,7 @@ bool QgsVectorLayer::deleteAttributes( QList<int> attrs )
21822185

21832186
qSort( attrs.begin(), attrs.end(), qGreater<int>() );
21842187

2185-
Q_FOREACH ( int attr, attrs )
2188+
Q_FOREACH( int attr, attrs )
21862189
{
21872190
if ( deleteAttribute( attr ) )
21882191
{
@@ -2622,13 +2625,19 @@ bool QgsVectorLayer::isModified() const
26222625

26232626
QgsVectorLayer::EditType QgsVectorLayer::editType( int idx )
26242627
{
2628+
if ( idx < 0 || idx >= mUpdatedFields.count() )
2629+
return Hidden;
2630+
26252631
Q_NOWARN_DEPRECATED_PUSH
26262632
return QgsLegacyHelpers::convertEditType( editorWidgetV2( idx ), editorWidgetV2Config( idx ), this, mUpdatedFields[ idx ].name() );
26272633
Q_NOWARN_DEPRECATED_POP
26282634
}
26292635

26302636
void QgsVectorLayer::setEditType( int idx, EditType type )
26312637
{
2638+
if ( idx < 0 || idx >= mUpdatedFields.count() )
2639+
return;
2640+
26322641
QgsEditorWidgetConfig cfg;
26332642

26342643
Q_NOWARN_DEPRECATED_PUSH
@@ -2651,11 +2660,17 @@ void QgsVectorLayer::setEditorLayout( EditorLayout editorLayout )
26512660

26522661
void QgsVectorLayer::setEditorWidgetV2( int attrIdx, const QString& widgetType )
26532662
{
2663+
if ( attrIdx < 0 || attrIdx >= mUpdatedFields.count() )
2664+
return;
2665+
26542666
mEditorWidgetV2Types[ mUpdatedFields[ attrIdx ].name()] = widgetType;
26552667
}
26562668

26572669
void QgsVectorLayer::setEditorWidgetV2Config( int attrIdx, const QgsEditorWidgetConfig& config )
26582670
{
2671+
if ( attrIdx < 0 || attrIdx >= mUpdatedFields.count() )
2672+
return;
2673+
26592674
mEditorWidgetV2Configs[ mUpdatedFields[ attrIdx ].name()] = config;
26602675
}
26612676

@@ -2940,7 +2955,7 @@ void QgsVectorLayer::uniqueValues( int index, QList<QVariant> &uniqueValues, int
29402955
if ( mEditBuffer )
29412956
{
29422957
QSet<QString> vals;
2943-
Q_FOREACH ( const QVariant& v, uniqueValues )
2958+
Q_FOREACH( const QVariant& v, uniqueValues )
29442959
{
29452960
vals << v.toString();
29462961
}
@@ -3748,7 +3763,7 @@ void QgsVectorLayer::invalidateSymbolCountedFlag()
37483763

37493764
void QgsVectorLayer::onRelationsLoaded()
37503765
{
3751-
Q_FOREACH ( QgsAttributeEditorElement* elem, mAttributeEditorElements )
3766+
Q_FOREACH( QgsAttributeEditorElement* elem, mAttributeEditorElements )
37523767
{
37533768
if ( elem->type() == QgsAttributeEditorElement::AeTypeContainer )
37543769
{
@@ -3757,7 +3772,7 @@ void QgsVectorLayer::onRelationsLoaded()
37573772
continue;
37583773

37593774
QList<QgsAttributeEditorElement*> relations = cont->findElements( QgsAttributeEditorElement::AeTypeRelation );
3760-
Q_FOREACH ( QgsAttributeEditorElement* relElem, relations )
3775+
Q_FOREACH( QgsAttributeEditorElement* relElem, relations )
37613776
{
37623777
QgsAttributeEditorRelation* rel = dynamic_cast< QgsAttributeEditorRelation* >( relElem );
37633778
if ( !rel )
@@ -3826,7 +3841,7 @@ QDomElement QgsAttributeEditorContainer::toDomElement( QDomDocument& doc ) const
38263841
QDomElement elem = doc.createElement( "attributeEditorContainer" );
38273842
elem.setAttribute( "name", mName );
38283843

3829-
Q_FOREACH ( QgsAttributeEditorElement* child, mChildren )
3844+
Q_FOREACH( QgsAttributeEditorElement* child, mChildren )
38303845
{
38313846
elem.appendChild( child->toDomElement( doc ) );
38323847
}
@@ -3842,7 +3857,7 @@ QList<QgsAttributeEditorElement*> QgsAttributeEditorContainer::findElements( Qgs
38423857
{
38433858
QList<QgsAttributeEditorElement*> results;
38443859

3845-
Q_FOREACH ( QgsAttributeEditorElement* elem, mChildren )
3860+
Q_FOREACH( QgsAttributeEditorElement* elem, mChildren )
38463861
{
38473862
if ( elem->type() == type )
38483863
{

0 commit comments

Comments
 (0)