Skip to content
Permalink
Browse files

Merge pull request #36873 from rouault/cppcheck_gh_action

Fix remaining cppcheck warnings, add scripts/cppcheck.sh and corresponding GH workflow jobs
  • Loading branch information
rouault committed Jun 2, 2020
2 parents dd86a5a + 9df71ef commit b4f5b48b35532e6109985da1ef5f1700630013f2
Showing with 613 additions and 396 deletions.
  1. +26 −0 .github/workflows/code_layout.yml
  2. +1 −1 python/core/auto_generated/diagram/qgsdiagram.sip.in
  3. +1 −1 python/core/auto_generated/diagram/qgshistogramdiagram.sip.in
  4. +1 −1 python/core/auto_generated/diagram/qgspiediagram.sip.in
  5. +1 −1 python/core/auto_generated/diagram/qgsstackedbardiagram.sip.in
  6. +1 −1 python/core/auto_generated/diagram/qgstextdiagram.sip.in
  7. +1 −1 python/core/auto_generated/effects/qgsblureffect.sip.in
  8. +1 −1 python/core/auto_generated/effects/qgscoloreffect.sip.in
  9. +1 −1 python/core/auto_generated/effects/qgseffectstack.sip.in
  10. +2 −2 python/core/auto_generated/effects/qgspainteffect.sip.in
  11. +3 −3 python/core/auto_generated/effects/qgsshadoweffect.sip.in
  12. +1 −1 python/core/auto_generated/effects/qgstransformeffect.sip.in
  13. +1 −0 python/core/auto_generated/layertree/qgslayertreenode.sip.in
  14. +1 −0 python/server/auto_generated/qgsaccesscontrol.sip.in
  15. +70 −0 scripts/cppcheck.sh
  16. +2 −4 src/3d/mesh/qgsmesh3dentity_p.cpp
  17. +2 −0 src/3d/symbols/qgspoint3dsymbol.h
  18. +1 −1 src/analysis/processing/qgsalgorithmgrid.cpp
  19. +2 −2 src/analysis/processing/qgsalgorithmrandompointsextent.cpp
  20. +1 −1 src/analysis/processing/qgsalgorithmzonalhistogram.cpp
  21. +2 −0 src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.h
  22. +25 −25 src/analysis/vector/qgszonalstatistics.cpp
  23. +3 −3 src/app/dwg/qgsdwgimporter.cpp
  24. +2 −0 src/app/georeferencer/qgsgeorefdatapoint.h
  25. +1 −0 src/app/georeferencer/qgsgeoreftransform.h
  26. +1 −1 src/app/qgisapp.cpp
  27. +3 −3 src/app/qgsapplayertreeviewmenuprovider.cpp
  28. +2 −1 src/core/diagram/qgsdiagram.h
  29. +1 −1 src/core/diagram/qgshistogramdiagram.h
  30. +1 −1 src/core/diagram/qgspiediagram.h
  31. +1 −1 src/core/diagram/qgsstackedbardiagram.h
  32. +1 −1 src/core/diagram/qgstextdiagram.h
  33. +1 −1 src/core/effects/qgsblureffect.h
  34. +1 −1 src/core/effects/qgscoloreffect.h
  35. +1 −1 src/core/effects/qgseffectstack.h
  36. +4 −2 src/core/effects/qgspainteffect.h
  37. +3 −3 src/core/effects/qgsshadoweffect.h
  38. +1 −1 src/core/effects/qgstransformeffect.h
  39. +2 −0 src/core/expression/qgsexpression_p.h
  40. +4 −1 src/core/geometry/qgsgeometrycollection.cpp
  41. +1 −1 src/core/geometry/qgswkbtypes.h
  42. +1 −1 src/core/labeling/qgslabelfeature.h
  43. +2 −0 src/core/layertree/qgslayertree.h
  44. +2 −0 src/core/layertree/qgslayertreegroup.h
  45. +2 −0 src/core/layertree/qgslayertreelayer.h
  46. +3 −0 src/core/layertree/qgslayertreenode.h
  47. +69 −80 src/core/layout/qgsabstractreportsection.cpp
  48. +10 −13 src/core/layout/qgslayoutitemattributetable.cpp
  49. +2 −0 src/core/pal/feature.h
  50. +1 −0 src/core/pal/labelposition.h
  51. +2 −0 src/core/pal/pointset.h
  52. +1 −0 src/core/pal/problem.cpp
  53. +1 −1 src/core/processing/models/qgsprocessingmodelalgorithm.cpp
  54. +5 −5 src/core/processing/qgsprocessingparameters.cpp
  55. +1 −0 src/core/qgsabstractcontentcache.h
  56. +3 −0 src/core/qgsarchive.cpp
  57. +11 −4 src/core/qgscoordinatereferencesystem_p.h
  58. +3 −0 src/core/qgscoordinatetransform.cpp
  59. +3 −0 src/core/qgscoordinatetransform_p.cpp
  60. +2 −0 src/core/qgscoordinatetransform_p.h
  61. +3 −1 src/core/qgscoordinatetransformcontext_p.h
  62. +2 −0 src/core/qgsdiagramrenderer.h
  63. +3 −0 src/core/qgseditformconfig_p.h
  64. +3 −0 src/core/qgsfeature_p.h
  65. +1 −1 src/core/qgsfeaturesource.cpp
  66. +2 −2 src/core/qgsfield.cpp
  67. +3 −0 src/core/qgsfield_p.h
  68. +1 −1 src/core/qgsfieldconstraints.cpp
  69. +2 −0 src/core/qgsfields.h
  70. +2 −0 src/core/qgsfields_p.h
  71. +2 −0 src/core/qgsproperty_p.h
  72. +1 −1 src/core/qgspropertycollection.cpp
  73. +1 −0 src/core/qgsrendercontext.cpp
  74. +1 −1 src/core/qgssnappingutils.cpp
  75. +2 −2 src/core/qgsspatialindex.cpp
  76. +1 −1 src/core/qgsvectorfilewriter.cpp
  77. +2 −0 src/core/raster/qgscontrastenhancementfunction.h
  78. +2 −4 src/core/raster/qgsrasterchecker.cpp
  79. +1 −0 src/core/symbology/qgssymbol.cpp
  80. +14 −1 src/core/textrenderer/qgstextrenderer_p.h
  81. +1 −1 src/crashhandler/qgscrashreport.h
  82. +2 −2 src/gui/editorwidgets/qgsdefaultsearchwidgetwrapper.cpp
  83. +2 −5 src/gui/layout/qgslayoutlegendwidget.cpp
  84. +2 −0 src/gui/processing/models/qgsmodeldesignerdialog.h
  85. +1 −1 src/gui/processing/qgsprocessingtoolboxmodel.cpp
  86. +1 −0 src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
  87. +1 −1 src/gui/qgsfontbutton.cpp
  88. +0 −1 src/plugins/grass/qgsgrassmodule.h
  89. +1 −1 src/plugins/grass/qtermwidget/BlockArray.h
  90. +0 −10 src/plugins/grass/qtermwidget/CharacterColor.h
  91. +2 −0 src/plugins/grass/qtermwidget/ColorScheme.h
  92. +2 −1 src/providers/oracle/ocispatial/qsql_ocispatial.cpp
  93. +2 −0 src/providers/oracle/qgsoracleprovider.h
  94. +2 −0 src/providers/wcs/qgswcscapabilities.h
  95. +2 −0 src/quickgui/qgsquickmapcanvasmap.cpp
  96. +13 −0 src/server/qgsaccesscontrol.h
  97. +225 −184 tests/src/core/testqgslabelingengine.cpp
@@ -158,3 +158,29 @@ jobs:
run: ./tests/code_layout/test_sip_include.sh
- name: Sip Files Up To Date
run: ./tests/code_layout/test_sipfiles_uptodate.sh

cppcheck_16_04:
runs-on: ubuntu-16.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Requirements
run: |
sudo apt install -y cppcheck
- name: Run cppcheck test
run: ./scripts/cppcheck.sh

cppcheck_18_04:
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Requirements
run: |
sudo apt install -y cppcheck
- name: Run cppcheck test
run: ./scripts/cppcheck.sh
@@ -9,7 +9,7 @@



class QgsDiagram
class QgsDiagram /NoDefaultCtors/
{
%Docstring
Base class for all diagram types*
@@ -11,7 +11,7 @@



class QgsHistogramDiagram: QgsDiagram
class QgsHistogramDiagram: QgsDiagram /NoDefaultCtors/
{

%TypeHeaderCode
@@ -9,7 +9,7 @@



class QgsPieDiagram: QgsDiagram
class QgsPieDiagram: QgsDiagram /NoDefaultCtors/
{

%TypeHeaderCode
@@ -11,7 +11,7 @@



class QgsStackedBarDiagram: QgsDiagram
class QgsStackedBarDiagram: QgsDiagram /NoDefaultCtors/
{
%Docstring

@@ -9,7 +9,7 @@



class QgsTextDiagram: QgsDiagram
class QgsTextDiagram: QgsDiagram /NoDefaultCtors/
{

%TypeHeaderCode
@@ -9,7 +9,7 @@



class QgsBlurEffect : QgsPaintEffect
class QgsBlurEffect : QgsPaintEffect /NoDefaultCtors/
{
%Docstring
A paint effect which blurs a source picture, using a number of different blur
@@ -9,7 +9,7 @@



class QgsColorEffect : QgsPaintEffect
class QgsColorEffect : QgsPaintEffect /NoDefaultCtors/
{
%Docstring
A paint effect which alters the colors (e.g., brightness, contrast) in a
@@ -9,7 +9,7 @@



class QgsEffectStack : QgsPaintEffect
class QgsEffectStack : QgsPaintEffect /NoDefaultCtors/
{
%Docstring
A paint effect which consists of a stack of other chained paint effects
@@ -10,7 +10,7 @@



class QgsPaintEffect
class QgsPaintEffect /NoDefaultCtors/
{
%Docstring
Base class for visual effects which can be applied to QPicture drawings
@@ -319,7 +319,7 @@ to rendering results onto a painter.
};


class QgsDrawSourceEffect : QgsPaintEffect
class QgsDrawSourceEffect : QgsPaintEffect /NoDefaultCtors/
{
%Docstring
A paint effect which draws the source picture with minor or no alterations
@@ -9,7 +9,7 @@



class QgsShadowEffect : QgsPaintEffect
class QgsShadowEffect : QgsPaintEffect /NoDefaultCtors/
{
%Docstring
Base class for paint effects which offset, blurred shadows
@@ -295,7 +295,7 @@ the picture.
};


class QgsDropShadowEffect : QgsShadowEffect
class QgsDropShadowEffect : QgsShadowEffect /NoDefaultCtors/
{
%Docstring
A paint effect which draws an offset and optionally blurred drop shadow
@@ -331,7 +331,7 @@ Creates a new QgsDropShadowEffect effect from a properties string map.

};

class QgsInnerShadowEffect : QgsShadowEffect
class QgsInnerShadowEffect : QgsShadowEffect /NoDefaultCtors/
{
%Docstring
A paint effect which draws an offset and optionally blurred drop shadow
@@ -9,7 +9,7 @@



class QgsTransformEffect : QgsPaintEffect
class QgsTransformEffect : QgsPaintEffect /NoDefaultCtors/
{
%Docstring
A paint effect which applies transformations (such as move,
@@ -313,6 +313,7 @@ Low-level removal of children from the node.
%End

protected:

};


@@ -38,6 +38,7 @@ Constructor

~QgsAccessControl();


void resolveFilterFeatures( const QList<QgsMapLayer *> &layers );
%Docstring
Resolve features' filter of layers
@@ -0,0 +1,70 @@
#!/bin/sh

set -eu

SCRIPT_DIR=$(dirname "$0")
case $SCRIPT_DIR in
"/"*)
;;
".")
SCRIPT_DIR=$(pwd)
;;
*)
SCRIPT_DIR=$(pwd)/$(dirname "$0")
;;
esac

LOG_FILE=/tmp/cppcheck_qgis.txt

rm -f ${LOG_FILE}
echo "Checking ${SCRIPT_DIR}/../src ..."

cppcheck --library=qt.cfg --inline-suppr \
--template='{file}:{line},{severity},{id},{message}' \
--enable=all --inconclusive --std=c++11 \
-DPROJ_VERSION_MAJOR=6 \
-USIP_RUN \
-DSIP_TRANSFER= \
-DSIP_TRANSFERTHIS= \
-DSIP_INOUT= \
-DSIP_OUT= \
-j $(nproc) \
${SCRIPT_DIR}/../src \
>>${LOG_FILE} 2>&1 &

PID=$!
while kill -0 $PID 2>/dev/null; do
printf "."
sleep 1
done
echo " done"
if ! wait $PID; then
echo "cppcheck failed"
exit 1
fi

ret_code=0

for category in "error" "style" "performance" "portability"; do
if grep "${category}," ${LOG_FILE} >/dev/null; then
echo "INFO: Issues in '${category}' category found, but not considered as making script to fail:"
grep "${category}," ${LOG_FILE} | grep -v "clarifyCalculation,"
echo ""
fi
done

for category in "warning" "clarifyCalculation"; do
if grep "${category}," ${LOG_FILE} >/dev/null; then
echo "ERROR: Issues in '${category}' category found:"
grep "${category}," ${LOG_FILE}
echo ""
echo "${category} check failed !"
ret_code=1
fi
done

if [ ${ret_code} = 0 ]; then
echo "cppcheck succeeded"
fi

exit ${ret_code}
@@ -49,11 +49,10 @@ void QgsMesh3dEntity::build()

void QgsMeshDataset3dEntity::buildGeometry()
{
Qt3DRender::QGeometryRenderer *mesh = new Qt3DRender::QGeometryRenderer;

if ( !layer() )
return;

Qt3DRender::QGeometryRenderer *mesh = new Qt3DRender::QGeometryRenderer;
mesh->setGeometry( new QgsMeshDataset3dGeometry( layer(), mMapSettings.temporalRange(), mMapSettings.origin(), mSymbol, mesh ) );
addComponent( mesh );
}
@@ -82,11 +81,10 @@ QgsMesh3dTerrainTileEntity::QgsMesh3dTerrainTileEntity( const Qgs3DMapSettings &

void QgsMesh3dTerrainTileEntity::buildGeometry()
{
Qt3DRender::QGeometryRenderer *mesh = new Qt3DRender::QGeometryRenderer;

if ( !layer() )
return;

Qt3DRender::QGeometryRenderer *mesh = new Qt3DRender::QGeometryRenderer;
mesh->setGeometry( new QgsMeshTerrain3dGeometry( layer(), mMapSettings.origin(), mSymbol, mesh ) );
addComponent( mesh );
}
@@ -112,6 +112,8 @@ class _3D_EXPORT QgsPoint3DSymbol : public QgsAbstract3DSymbol
std::unique_ptr<QgsMarkerSymbol> mBillboardSymbol;
#ifdef SIP_RUN
QgsPoint3DSymbol &operator=( const QgsPoint3DSymbol & );
#else
QgsPoint3DSymbol &operator=( const QgsPoint3DSymbol & ) = delete;
#endif
};

@@ -286,7 +286,7 @@ void QgsGridAlgorithm::createLineGrid( std::unique_ptr< QgsFeatureSink > &sink,

while ( x <= mGridExtent.xMaximum() )
{
if ( feedback && feedback->isCanceled() )
if ( feedback->isCanceled() )
break;

QgsPoint pt1 = QgsPoint( x, mGridExtent.yMaximum() );
@@ -113,7 +113,7 @@ QVariantMap QgsRandomPointsExtentAlgorithm::processAlgorithm( const QVariantMap
int i = 0;
while ( i < mNumPoints )
{
if ( feedback && feedback->isCanceled() )
if ( feedback->isCanceled() )
break;

double rx = x_distribution( random_device );
@@ -136,7 +136,7 @@ QVariantMap QgsRandomPointsExtentAlgorithm::processAlgorithm( const QVariantMap
int i = 0;
while ( i < mNumPoints )
{
if ( feedback && feedback->isCanceled() )
if ( feedback->isCanceled() )
break;

double rx = x_distribution( random_device );
@@ -116,7 +116,7 @@ QVariantMap QgsZonalHistogramAlgorithm::processAlgorithm( const QVariantMap &par
QgsFeature f;
while ( it.nextFeature( f ) )
{
if ( feedback && feedback->isCanceled() )
if ( feedback->isCanceled() )
{
break;
}
@@ -180,6 +180,8 @@ class ANALYSIS_EXPORT QgsGeometryCheckerUtils
QgsFeatureIds::const_iterator mFeatureIt;
const LayerFeatures *mParent = nullptr;
std::unique_ptr<QgsGeometryCheckerUtils::LayerFeature> mCurrentFeature;

iterator &operator= ( const iterator & ) = delete;
};

/**
@@ -173,31 +173,31 @@ int QgsZonalStatistics::calculateStatistics( QgsFeedback *feedback )
vectorProvider->addAttributes( newFieldList );

//index of the new fields
int countIndex = mStatistics & QgsZonalStatistics::Count ? vectorProvider->fieldNameIndex( countFieldName ) : -1;
int sumIndex = mStatistics & QgsZonalStatistics::Sum ? vectorProvider->fieldNameIndex( sumFieldName ) : -1;
int meanIndex = mStatistics & QgsZonalStatistics::Mean ? vectorProvider->fieldNameIndex( meanFieldName ) : -1;
int medianIndex = mStatistics & QgsZonalStatistics::Median ? vectorProvider->fieldNameIndex( medianFieldName ) : -1;
int stdevIndex = mStatistics & QgsZonalStatistics::StDev ? vectorProvider->fieldNameIndex( stdevFieldName ) : -1;
int minIndex = mStatistics & QgsZonalStatistics::Min ? vectorProvider->fieldNameIndex( minFieldName ) : -1;
int maxIndex = mStatistics & QgsZonalStatistics::Max ? vectorProvider->fieldNameIndex( maxFieldName ) : -1;
int rangeIndex = mStatistics & QgsZonalStatistics::Range ? vectorProvider->fieldNameIndex( rangeFieldName ) : -1;
int minorityIndex = mStatistics & QgsZonalStatistics::Minority ? vectorProvider->fieldNameIndex( minorityFieldName ) : -1;
int majorityIndex = mStatistics & QgsZonalStatistics::Majority ? vectorProvider->fieldNameIndex( majorityFieldName ) : -1;
int varietyIndex = mStatistics & QgsZonalStatistics::Variety ? vectorProvider->fieldNameIndex( varietyFieldName ) : -1;
int varianceIndex = mStatistics & QgsZonalStatistics::Variance ? vectorProvider->fieldNameIndex( varianceFieldName ) : -1;

if ( ( mStatistics & QgsZonalStatistics::Count && countIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Sum && sumIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Mean && meanIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Median && medianIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::StDev && stdevIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Min && minIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Max && maxIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Range && rangeIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Minority && minorityIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Majority && majorityIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Variety && varietyIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Variance && varianceIndex == -1 )
int countIndex = ( mStatistics & QgsZonalStatistics::Count ) ? vectorProvider->fieldNameIndex( countFieldName ) : -1;
int sumIndex = ( mStatistics & QgsZonalStatistics::Sum ) ? vectorProvider->fieldNameIndex( sumFieldName ) : -1;
int meanIndex = ( mStatistics & QgsZonalStatistics::Mean ) ? vectorProvider->fieldNameIndex( meanFieldName ) : -1;
int medianIndex = ( mStatistics & QgsZonalStatistics::Median ) ? vectorProvider->fieldNameIndex( medianFieldName ) : -1;
int stdevIndex = ( mStatistics & QgsZonalStatistics::StDev ) ? vectorProvider->fieldNameIndex( stdevFieldName ) : -1;
int minIndex = ( mStatistics & QgsZonalStatistics::Min ) ? vectorProvider->fieldNameIndex( minFieldName ) : -1;
int maxIndex = ( mStatistics & QgsZonalStatistics::Max ) ? vectorProvider->fieldNameIndex( maxFieldName ) : -1;
int rangeIndex = ( mStatistics & QgsZonalStatistics::Range ) ? vectorProvider->fieldNameIndex( rangeFieldName ) : -1;
int minorityIndex = ( mStatistics & QgsZonalStatistics::Minority ) ? vectorProvider->fieldNameIndex( minorityFieldName ) : -1;
int majorityIndex = ( mStatistics & QgsZonalStatistics::Majority ) ? vectorProvider->fieldNameIndex( majorityFieldName ) : -1;
int varietyIndex = ( mStatistics & QgsZonalStatistics::Variety ) ? vectorProvider->fieldNameIndex( varietyFieldName ) : -1;
int varianceIndex = ( mStatistics & QgsZonalStatistics::Variance ) ? vectorProvider->fieldNameIndex( varianceFieldName ) : -1;

if ( ( ( mStatistics & QgsZonalStatistics::Count ) && countIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Sum ) && sumIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Mean ) && meanIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Median ) && medianIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::StDev ) && stdevIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Min ) && minIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Max ) && maxIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Range ) && rangeIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Minority ) && minorityIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Majority ) && majorityIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Variety ) && varietyIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Variance ) && varianceIndex == -1 )
)
{
//failed to create a required field

0 comments on commit b4f5b48

Please sign in to comment.
You can’t perform that action at this time.