Even Rouault wrote:
Ramiro,

It is illegal to change the layer definition with CreateField() if you have pre-existing features of that layer. This is documented here : http://www.gdal.org/ogr/classOGRFeatureDefn.html#40e681d8464b42f1a1fac655f16ac3dd

Illegal yes, but IMHO segfault should never be an option in a case like this. Just consider an interactive program with real-time scripting with one of the bindings languages.

The segfault happens in this case in OGRFeature::IsFieldSet (ogr_feature.h:193), which does not check that iField is within legal limits. The method could check that iField is less or equal to poDefn->nFieldCount. That should not be a problem. Probably similar checks could/should be done in other methods as well.

At least in shape driver the layer does not assume that the feature schema is exactly the same as in layer: it asks the data from the feature using type casting methods (GetFieldAsInteger and friends).

I'm going to make a bug report from this.

Best regards,

Ari

There's no way to check if the feature is "valid". So, just don't do it ;-)

Le Tuesday 27 April 2010 21:17:17 Ramiro Gonzalez, vous avez écrit :
My application uses OGR to edit ESRI Shapefiles.

If I follow this steps:

1_ Create a feature(OGRFeature::CreateFeature) using the feature definition
from an existing layer(layerA)
2_ Add a field (OGRLayer::CreateField) to layerA
3_ Try to save the feature (OGRLayer::SetFeature) in layerA

I receive a SIGSEGV from function OGRFeature::SetField. I believe this
happens because I modify the layer definition in step 2 leaving the feature
definition out of date.

I'd like to know if there is any way to check if the feature is valid
before calling SetFeature.

Thanks
Ramiro


_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to