Dereferencing a null dataProvider() seems to me to be a recurrent class
of (crashing) bugs (I've for sure fixed such issues several times)
My idea is probably a bit silly, but what about
https://gist.github.com/rouault/ed533d30738bda806ebeaa47f0877e2c ?
Basically:
- deprecate dataProvider() for C++, with a GCC
__attribute__((deprecated()) annotation so we can spot all occurrences
- replace it with dataProviderNullable() which returns a
QgsVectorDataProviderPtr structure that encapsulates the raw pointer and
have a get() method to get it
So you have to replace code like:
mTracksLayer->dataProvider()->addFeature( feature,
QgsFeatureSink::Flag::FastInsert );
with
if ( auto provider = mTracksLayer->dataProviderNullablePtr().get() )
{
provider->addFeature( feature, QgsFeatureSink::Flag::FastInsert );
}
Of course someone could still do
mTracksLayer->dataProviderNullablePtr().get()->addFeature( ... ) but
that should be obvious they are cheating... And I guess some linting
script could catch "dataProviderNullablePtr().get()->" buggy/risky patterns
And of course it forces checking for null in places where it cannot be,
but perhaps be on the safe side...
Another alternative I thought was to have dataProvider() return a dummy
non-null instance if mDataProvider is null, but that's probably not a
good idea.
Even
Le 02/02/2023 à 02:19, Nyall Dawson via QGIS-Developer a écrit :
Hi PSC/list,
I came across this horrible regression during bug hunting today:
https://github.com/qgis/QGIS/pull/51703
If you load a project with any broken layers and then hover over the
layer in the layer tree, QGIS will instantly crash. It's a regression
caused by https://github.com/qgis/QGIS/pull/50256, and unfortunately
that PR was backported to 3.22 and accordingly the crash present in
the final release of 3.22.
Given the extreme severity of this crash I believe we should be
pushing out another unplanned 3.22 patch release, as we cannot leave
the final 3.22 LTR with such a nasty regression in place.
Nyall
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
--
http://www.spatialys.com
My software is free, but my time generally not.
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer