Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix crash in expression array functions on qt6
Calling *std::min_element/max_element on an empty container
leads to a crash
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Jul 20, 2021
1 parent 1c3c5cd commit 1099dbd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -5501,6 +5501,9 @@ static QVariant fcnArrayMajority( const QVariantList &values, const QgsExpressio
++hash[item];
}
const QList< int > occurrences = hash.values();
if ( occurrences.empty() )
return QVariantList();

const int maxValue = *std::max_element( occurrences.constBegin(), occurrences.constEnd() );

const QString option = values.at( 1 ).toString();
Expand Down Expand Up @@ -5542,6 +5545,9 @@ static QVariant fcnArrayMinority( const QVariantList &values, const QgsExpressio
++hash[item];
}
const QList< int > occurrences = hash.values();
if ( occurrences.empty() )
return QVariantList();

const int minValue = *std::min_element( occurrences.constBegin(), occurrences.constEnd() );

const QString option = values.at( 1 ).toString();
Expand Down

0 comments on commit 1099dbd

Please sign in to comment.