Avoid coverity uncaught exception warnings

The warning is a false positive, since we were already checking
that the optional has a value before accessing it. But we can
avoid the exception altogether (and gain some performance) by
using the std::optional dereference operator, which DOES not
throw and which relies on the previous has_value check to avoid
undefined behavior.
This commit is contained in:
Nyall Dawson 2025-02-12 14:38:28 +10:00
parent 8f170a6830
commit e3762c5f6e
No known key found for this signature in database
GPG Key ID: 4C61673F0BF197FC
4 changed files with 5 additions and 5 deletions

View File

@ -232,7 +232,7 @@ QVector<QgsProfileIdentifyResults> QgsAbstractProfileSurfaceResults::identify( c
prevElevation = it.value();
}
if ( result.has_value() )
return {result.value()};
return {*result};
else
return {};
}

View File

@ -83,7 +83,7 @@ class CORE_EXPORT QgsTextLabelFeature : public QgsLabelFeature
* \see setTextMetrics()
* \since QGIS 3.20
*/
const QgsPrecalculatedTextMetrics *textMetrics() const { return mTextMetrics.has_value() ? &mTextMetrics.value() : nullptr; }
const QgsPrecalculatedTextMetrics *textMetrics() const { return mTextMetrics.has_value() ? &( *mTextMetrics ) : nullptr; }
/**
* Sets additional text \a metrics required for curved label placement.

View File

@ -264,7 +264,7 @@ struct MapIndexedPointCloudNode
// here we check the flag set in header to determine if we need to
// parse the time as GPS week time or GPS adjusted standard time
// however often times the flag is set wrong, so we determine if the value is bigger than the maximum amount of seconds in week then it has to be adjusted standard time
if ( copcTimeFlag.value() || pointAttr[QStringLiteral( "GpsTime" )].toDouble() > numberOfSecsInWeek )
if ( *copcTimeFlag || pointAttr[QStringLiteral( "GpsTime" )].toDouble() > numberOfSecsInWeek )
{
const QString utcTime = gpsBaseTime.addSecs( static_cast<qint64>( pointAttr[QStringLiteral( "GpsTime" )].toDouble() + 1e9 ) ).toString( Qt::ISODate );
pointAttr[ QStringLiteral( "GpsTime (raw)" )] = pointAttr[QStringLiteral( "GpsTime" )];

View File

@ -48,7 +48,7 @@ class CORE_EXPORT QgsSettingsProxy
*/
QgsSettings *operator->()
{
return mOwnedSettings.has_value() ? &( mOwnedSettings.value() ) : mNonOwnedSettings;
return mOwnedSettings.has_value() ? &( *mOwnedSettings ) : mNonOwnedSettings;
}
/**
@ -56,7 +56,7 @@ class CORE_EXPORT QgsSettingsProxy
*/
QgsSettings &operator* ()
{
return mOwnedSettings.has_value() ? mOwnedSettings.value() : *mNonOwnedSettings;
return mOwnedSettings.has_value() ? *mOwnedSettings : *mNonOwnedSettings;
}
private: