From 4c7eb8327bcbce0724ae9966bc0baec372179b84 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Fri, 27 Oct 2017 15:15:24 +0200 Subject: [PATCH] Fix crash when accessing out of bounds field --- src/gui/qgsattributeform.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gui/qgsattributeform.cpp b/src/gui/qgsattributeform.cpp index 77b029619a8..bba049239b1 100644 --- a/src/gui/qgsattributeform.cpp +++ b/src/gui/qgsattributeform.cpp @@ -1514,8 +1514,9 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt if ( !fieldDef ) break; - int fldIdx = vl->fields().lookupField( fieldDef->name() ); - if ( fldIdx < vl->fields().count() && fldIdx >= 0 ) + const QgsFields fields = vl->fields(); + int fldIdx = fields.lookupField( fieldDef->name() ); + if ( fldIdx < fields.count() && fldIdx >= 0 ) { const QgsEditorWidgetSetup widgetSetup = QgsGui::editorWidgetRegistry()->findBest( mLayer, fieldDef->name() ); @@ -1528,12 +1529,12 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt newWidgetInfo.widget = w; addWidgetWrapper( eww ); - newWidgetInfo.widget->setObjectName( mLayer->fields().at( fldIdx ).name() ); + newWidgetInfo.widget->setObjectName( fields.at( fldIdx ).name() ); + newWidgetInfo.hint = fields.at( fieldDef->idx() ).comment(); } newWidgetInfo.labelOnTop = mLayer->editFormConfig().labelOnTop( fieldDef->idx() ); newWidgetInfo.labelText = mLayer->attributeDisplayName( fieldDef->idx() ); - newWidgetInfo.hint = mLayer->fields().at( fieldDef->idx() ).comment(); newWidgetInfo.showLabel = widgetDef->showLabel(); break;