Skip to content

Commit d19e707

Browse files
committed
Ensure all pointer variables are initialized to nullptr
1 parent 54339e3 commit d19e707

File tree

859 files changed

+2756
-2752
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

859 files changed

+2756
-2752
lines changed

scripts/unify_includes.pl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@
2828
# Also fix doxygen comments
2929
s#^(\s*)/\*[*!]\s*([^\s*].*)\s*$#$1/** \u$2\n#;
3030

31-
# Convert single line doxygent blocks:
31+
# Convert single line doxygen blocks:
3232
# /*!< comment */ to //!< comment
3333
# /** comment */ to //! comment
3434
s#\/\*[!\*](?!\*)(<*)\h*(.*?)\h*\*\/\h*$#//!$1 $2#;
3535

3636
# Uppercase initial character in //!< comment
3737
s#\/\/!<\s*(.)(.*)#//!< \u$1$2#;
3838

39+
# Ensure that pointer members are always initialized to nullptr
40+
# We don't run this check by default, there's a high likelihood of false positives...
41+
# s#^(\s*(?!typedef|return|delete)(?:\s*(?:const)\s*)?[a-zA-Z0-9_:]+\s*\*+\s*[a-zA-Z0-9_]+)\s*;\s*$#$1 = nullptr;\n#;
42+
3943
if( /^\s*#include/ ) {
4044
push @inc, $_ unless exists $inc{$_};
4145
$inc{$_}=1;

src/analysis/interpolation/CloughTocherInterpolator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ANALYSIS_EXPORT CloughTocherInterpolator : public TriangleInterpolator
2929
{
3030
protected:
3131
//! Association with a triangulation object
32-
NormVecDecorator* mTIN;
32+
NormVecDecorator* mTIN = nullptr;
3333
//! Tolerance of the barycentric coordinates at the borders of the triangles (to prevent errors because of very small negativ baricentric coordinates)
3434
double mEdgeTolerance;
3535
//! First point of the triangle in x-,y-,z-coordinates

src/analysis/interpolation/DualEdgeTriangulation.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,9 +2968,9 @@ bool DualEdgeTriangulation::swapEdge( double x, double y )
29682968
if ( edge1 >= 0 )
29692969
{
29702970
int edge2, edge3;
2971-
Point3D* point1;
2972-
Point3D* point2;
2973-
Point3D* point3;
2971+
Point3D* point1 = nullptr;
2972+
Point3D* point2 = nullptr;
2973+
Point3D* point3 = nullptr;
29742974
edge2 = mHalfEdge[edge1]->getNext();
29752975
edge3 = mHalfEdge[edge2]->getNext();
29762976
point1 = getPoint( mHalfEdge[edge1]->getPoint() );
@@ -3030,9 +3030,9 @@ QList<int>* DualEdgeTriangulation::getPointsAroundEdge( double x, double y )
30303030
if ( edge1 >= 0 )
30313031
{
30323032
int edge2, edge3;
3033-
Point3D* point1;
3034-
Point3D* point2;
3035-
Point3D* point3;
3033+
Point3D* point1 = nullptr;
3034+
Point3D* point2 = nullptr;
3035+
Point3D* point3 = nullptr;
30363036
edge2 = mHalfEdge[edge1]->getNext();
30373037
edge3 = mHalfEdge[edge2]->getNext();
30383038
point1 = getPoint( mHalfEdge[edge1]->getPoint() );

src/analysis/interpolation/DualEdgeTriangulation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
122122
//! Stores pointers to the HalfEdges
123123
QVector<HalfEdge*> mHalfEdge;
124124
//! Association to an interpolator object
125-
TriangleInterpolator* mTriangleInterpolator;
125+
TriangleInterpolator* mTriangleInterpolator = nullptr;
126126
//! Member to store the behavior in case of crossing forced segments
127127
Triangulation::ForcedCrossBehavior mForcedCrossBehavior;
128128
//! Color to paint the normal edges
@@ -132,7 +132,7 @@ class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
132132
//! Color to paint the breaklines
133133
QColor mBreakEdgeColor;
134134
//! Pointer to the decorator using this triangulation. It it is used directly, mDecorator equals this
135-
Triangulation* mDecorator;
135+
Triangulation* mDecorator = nullptr;
136136
//! Inserts an edge and makes sure, everything is ok with the storage of the edge. The number of the HalfEdge is returned
137137
unsigned int insertEdge( int dual, int next, int point, bool mbreak, bool forced );
138138
//! Inserts a forced segment between the points with the numbers p1 and p2 into the triangulation and returns the number of a HalfEdge belonging to this forced edge or -100 in case of failure

src/analysis/interpolation/LinTriangleInterpolator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ANALYSIS_EXPORT LinTriangleInterpolator : public TriangleInterpolator
4242

4343

4444
protected:
45-
DualEdgeTriangulation* mTIN;
45+
DualEdgeTriangulation* mTIN = nullptr;
4646
//! Calculates the first derivative with respect to x for a linear surface and assigns it to vec
4747
virtual bool calcFirstDerX( double x, double y, Vector3D* result );
4848
//! Calculates the first derivative with respect to y for a linear surface and assigns it to vec

src/analysis/interpolation/Line3D.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class ANALYSIS_EXPORT Line3D
3030
//! Assignment operator, declared private to not use it
3131
Line3D& operator=( const Line3D& );
3232
protected:
33-
Node* head;
34-
Node* z;
35-
Node* currentNode;
33+
Node* head = nullptr;
34+
Node* z = nullptr;
35+
Node* currentNode = nullptr;
3636
unsigned int size;
3737
unsigned int current;
3838

src/analysis/interpolation/Node.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class ANALYSIS_EXPORT Node
2626
{
2727
protected:
2828
//! Pointer to the Point3D object associated with the node
29-
Point3D* mPoint;
29+
Point3D* mPoint = nullptr;
3030
//! Pointer to the next Node in the linked list
31-
Node* mNext;
31+
Node* mNext = nullptr;
3232
public:
3333
Node();
3434
Node( const Node& n );

src/analysis/interpolation/NormVecDecorator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ANALYSIS_EXPORT NormVecDecorator: public TriDecorator
7474
bool alreadyestimated;
7575
static const unsigned int DEFAULT_STORAGE_FOR_NORMALS = 100000;
7676
//! Association with an interpolator object
77-
TriangleInterpolator* mInterpolator;
77+
TriangleInterpolator* mInterpolator = nullptr;
7878
//! Vector that stores the normals for the points. If 'estimateFirstDerivatives()' was called and there is a null pointer, this means, that the triangle point is on a breakline
7979
QVector<Vector3D*>* mNormVec;
8080
//! Vector who stores, it a point is not on a breakline, if it is a normal point of the breakline or if it is an endpoint of a breakline

src/analysis/interpolation/ParametricLine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ANALYSIS_EXPORT ParametricLine
3232
//! Degree of the parametric Line
3333
int mDegree;
3434
//! Pointer to the parent object. If there isn't one, mParent is 0
35-
ParametricLine* mParent;
35+
ParametricLine* mParent = nullptr;
3636
//! MControlPoly stores the points of the control polygon
3737
QVector<Point3D*>* mControlPoly;
3838
public:

src/analysis/interpolation/TriDecorator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ANALYSIS_EXPORT TriDecorator : public Triangulation
5858
virtual QList<int>* getPointsAroundEdge( double x, double y ) override;
5959
protected:
6060
//! Association with a Triangulation object
61-
Triangulation* mTIN;
61+
Triangulation* mTIN = nullptr;
6262
};
6363

6464
inline TriDecorator::TriDecorator(): mTIN( nullptr )

src/analysis/interpolation/qgsgridfilewriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ANALYSIS_EXPORT QgsGridFileWriter
4444
QgsGridFileWriter(); //forbidden
4545
int writeHeader( QTextStream& outStream );
4646

47-
QgsInterpolator* mInterpolator;
47+
QgsInterpolator* mInterpolator = nullptr;
4848
QString mOutputFilePath;
4949
QgsRectangle mInterpolationExtent;
5050
int mNumColumns;

src/analysis/interpolation/qgsinterpolator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ANALYSIS_EXPORT QgsInterpolator
4949
//! A layer together with the information about interpolation attribute / z-coordinate interpolation and the type (point, structure line, breakline)
5050
struct LayerData
5151
{
52-
QgsVectorLayer* vectorLayer;
52+
QgsVectorLayer* vectorLayer = nullptr;
5353
bool zCoordInterpolation;
5454
int interpolationAttribute;
5555
InputType mInputType;

src/analysis/interpolation/qgstininterpolator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class ANALYSIS_EXPORT QgsTINInterpolator: public QgsInterpolator
5151
void setTriangulationFilePath( const QString& filepath ) {mTriangulationFilePath = filepath;}
5252

5353
private:
54-
Triangulation* mTriangulation;
55-
TriangleInterpolator* mTriangleInterpolator;
54+
Triangulation* mTriangulation = nullptr;
55+
TriangleInterpolator* mTriangleInterpolator = nullptr;
5656
bool mIsInitialized;
5757
bool mShowProgressDialog;
5858
//! If true: export triangulation to shapefile after initialization

src/analysis/network/qgsgraphbuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ANALYSIS_EXPORT QgsGraphBuilder : public QgsGraphBuilderInterface
5656

5757
private:
5858

59-
QgsGraph *mGraph;
59+
QgsGraph *mGraph = nullptr;
6060
};
6161

6262
#endif // QGSGRAPHBUILDER_H

src/analysis/network/qgsvectorlayerdirector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ANALYSIS_EXPORT QgsVectorLayerDirector : public QgsGraphDirector
7777
QString name() const override;
7878

7979
private:
80-
QgsVectorLayer *mVectorLayer;
80+
QgsVectorLayer *mVectorLayer = nullptr;
8181
int mDirectionFieldId;
8282
QString mDirectDirectionValue;
8383
QString mReverseDirectionValue;

src/analysis/openstreetmap/qgsosmdatabase.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ bool QgsOSMDatabase::close()
9898

9999
int QgsOSMDatabase::runCountStatement( const char* sql ) const
100100
{
101-
sqlite3_stmt* stmt;
101+
sqlite3_stmt* stmt = nullptr;
102102
int res = sqlite3_prepare_v2( mDatabase, sql, -1, &stmt, nullptr );
103103
if ( res != SQLITE_OK )
104104
return -1;
@@ -182,7 +182,7 @@ QList<QgsOSMTagCountPair> QgsOSMDatabase::usedTags( bool ways ) const
182182

183183
QString sql = QStringLiteral( "SELECT k, count(k) FROM %1_tags GROUP BY k" ).arg( ways ? "ways" : "nodes" );
184184

185-
sqlite3_stmt* stmt;
185+
sqlite3_stmt* stmt = nullptr;
186186
if ( sqlite3_prepare_v2( mDatabase, sql.toUtf8().data(), -1, &stmt, nullptr ) != SQLITE_OK )
187187
return pairs;
188188

@@ -384,7 +384,7 @@ void QgsOSMDatabase::exportSpatiaLiteNodes( const QString& tableName, const QStr
384384
for ( int i = 0; i < tagKeys.count(); ++i )
385385
sqlInsertPoint += QStringLiteral( ",?" );
386386
sqlInsertPoint += QLatin1String( ", GeomFromWKB(?, 4326))" );
387-
sqlite3_stmt* stmtInsert;
387+
sqlite3_stmt* stmtInsert = nullptr;
388388
if ( sqlite3_prepare_v2( mDatabase, sqlInsertPoint.toUtf8().constData(), -1, &stmtInsert, nullptr ) != SQLITE_OK )
389389
{
390390
mError = QStringLiteral( "Prepare SELECT FROM nodes failed." );
@@ -451,7 +451,7 @@ void QgsOSMDatabase::exportSpatiaLiteWays( bool closed, const QString& tableName
451451
for ( int i = 0; i < tagKeys.count(); ++i )
452452
sqlInsertLine += QStringLiteral( ",?" );
453453
sqlInsertLine += QLatin1String( ", GeomFromWKB(?, 4326))" );
454-
sqlite3_stmt* stmtInsert;
454+
sqlite3_stmt* stmtInsert = nullptr;
455455
if ( sqlite3_prepare_v2( mDatabase, sqlInsertLine.toUtf8().constData(), -1, &stmtInsert, nullptr ) != SQLITE_OK )
456456
{
457457
mError = QStringLiteral( "Prepare SELECT FROM ways failed." );

src/analysis/openstreetmap/qgsosmdatabase.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ class ANALYSIS_EXPORT QgsOSMDatabase
117117
QString mError;
118118

119119
//! pointer to sqlite3 database that keeps OSM data
120-
sqlite3* mDatabase;
120+
sqlite3* mDatabase = nullptr;
121121

122-
sqlite3_stmt* mStmtNode;
123-
sqlite3_stmt* mStmtNodeTags;
124-
sqlite3_stmt* mStmtWay;
125-
sqlite3_stmt* mStmtWayNode;
126-
sqlite3_stmt* mStmtWayNodePoints;
127-
sqlite3_stmt* mStmtWayTags;
122+
sqlite3_stmt* mStmtNode = nullptr;
123+
sqlite3_stmt* mStmtNodeTags = nullptr;
124+
sqlite3_stmt* mStmtWay = nullptr;
125+
sqlite3_stmt* mStmtWayNode = nullptr;
126+
sqlite3_stmt* mStmtWayNodePoints = nullptr;
127+
sqlite3_stmt* mStmtWayTags = nullptr;
128128

129129
};
130130

@@ -147,7 +147,7 @@ class ANALYSIS_EXPORT QgsOSMNodeIterator // clazy:exclude=rule-of-three
147147
*/
148148
QgsOSMNodeIterator( sqlite3* handle );
149149

150-
sqlite3_stmt* mStmt;
150+
sqlite3_stmt* mStmt = nullptr;
151151

152152
friend class QgsOSMDatabase;
153153

@@ -173,7 +173,7 @@ class ANALYSIS_EXPORT QgsOSMWayIterator // clazy:exclude=rule-of-three
173173
*/
174174
QgsOSMWayIterator( sqlite3* handle );
175175

176-
sqlite3_stmt* mStmt;
176+
sqlite3_stmt* mStmt = nullptr;
177177

178178
friend class QgsOSMDatabase;
179179

src/analysis/openstreetmap/qgsosmdownload.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ANALYSIS_EXPORT QgsOSMDownload : public QObject
9696
QString mQuery;
9797
QString mError;
9898

99-
QNetworkReply* mReply;
99+
QNetworkReply* mReply = nullptr;
100100
QFile mFile;
101101
};
102102

src/analysis/openstreetmap/qgsosmimport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ bool QgsOSMXmlImport::createIndexes()
131131

132132
bool QgsOSMXmlImport::createDatabase()
133133
{
134-
char **results;
134+
char **results = nullptr;
135135
int rows, columns;
136136
if ( QgsSLConnect::sqlite3_open_v2( mDbFileName.toUtf8().data(), &mDatabase, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr ) != SQLITE_OK )
137137
return false;
@@ -165,7 +165,7 @@ bool QgsOSMXmlImport::createDatabase()
165165
int initCount = sizeof( sqlInitStatements ) / sizeof( const char* );
166166
for ( int i = 0; i < initCount; ++i )
167167
{
168-
char* errMsg;
168+
char* errMsg = nullptr;
169169
if ( sqlite3_exec( mDatabase, sqlInitStatements[i], nullptr, nullptr, &errMsg ) != SQLITE_OK )
170170
{
171171
mError = QStringLiteral( "Error executing SQL command:\n%1\nSQL:\n%2" )

src/analysis/openstreetmap/qgsosmimport.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ class ANALYSIS_EXPORT QgsOSMXmlImport : public QObject
8989

9090
QFile mInputFile;
9191

92-
sqlite3* mDatabase;
93-
sqlite3_stmt* mStmtInsertNode;
94-
sqlite3_stmt* mStmtInsertNodeTag;
95-
sqlite3_stmt* mStmtInsertWay;
96-
sqlite3_stmt* mStmtInsertWayNode;
97-
sqlite3_stmt* mStmtInsertWayTag;
92+
sqlite3* mDatabase = nullptr;
93+
sqlite3_stmt* mStmtInsertNode = nullptr;
94+
sqlite3_stmt* mStmtInsertNodeTag = nullptr;
95+
sqlite3_stmt* mStmtInsertWay = nullptr;
96+
sqlite3_stmt* mStmtInsertWayNode = nullptr;
97+
sqlite3_stmt* mStmtInsertWayTag = nullptr;
9898
};
9999

100100

src/analysis/raster/qgsalignraster.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class ANALYSIS_EXPORT QgsAlignRaster
238238
// set by the client
239239

240240
//! Object that facilitates reporting of progress / cancelation
241-
ProgressHandler* mProgressHandler;
241+
ProgressHandler* mProgressHandler = nullptr;
242242

243243
//! Last error message from run()
244244
QString mErrorMessage;

src/analysis/raster/qgskde.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ANALYSIS_EXPORT QgsKernelDensityEstimation
7171
struct Parameters
7272
{
7373
//! Vector point layer
74-
QgsVectorLayer* vectorLayer;
74+
QgsVectorLayer* vectorLayer = nullptr;
7575

7676
//! Fixed radius, in map units
7777
double radius;
@@ -146,7 +146,7 @@ class ANALYSIS_EXPORT QgsKernelDensityEstimation
146146

147147
QgsRectangle calculateBounds() const;
148148

149-
QgsVectorLayer* mInputLayer;
149+
QgsVectorLayer* mInputLayer = nullptr;
150150

151151
QString mOutputFile;
152152
QString mOutputFormat;

src/analysis/raster/qgsninecellfilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ GDALDatasetH QgsNineCellFilter::openInputFile( int& nCellsX, int& nCellsY )
230230

231231
GDALDriverH QgsNineCellFilter::openOutputDriver()
232232
{
233-
char **driverMetadata;
233+
char **driverMetadata = nullptr;
234234

235235
//open driver
236236
GDALDriverH outputDriver = GDALGetDriverByName( mOutputFormat.toLocal8Bit().data() );

src/analysis/raster/qgsrastercalcnode.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
102102

103103
private:
104104
Type mType;
105-
QgsRasterCalcNode* mLeft;
106-
QgsRasterCalcNode* mRight;
105+
QgsRasterCalcNode* mLeft = nullptr;
106+
QgsRasterCalcNode* mRight = nullptr;
107107
double mNumber;
108108
QString mRasterName;
109-
QgsRasterMatrix* mMatrix;
109+
QgsRasterMatrix* mMatrix = nullptr;
110110
Operator mOperator;
111111

112112
};

src/analysis/raster/qgsrastercalculator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ QgsRasterCalculator::QgsRasterCalculator()
188188

189189
GDALDriverH QgsRasterCalculator::openOutputDriver()
190190
{
191-
char **driverMetadata;
191+
char **driverMetadata = nullptr;
192192

193193
//open driver
194194
GDALDriverH outputDriver = GDALGetDriverByName( mOutputFormat.toLocal8Bit().data() );

src/analysis/raster/qgsrastermatrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class ANALYSIS_EXPORT QgsRasterMatrix
115115
private:
116116
int mColumns;
117117
int mRows;
118-
double* mData;
118+
double* mData = nullptr;
119119
double mNodataValue;
120120

121121
//! +,-,*,/,^,<,>,<=,>=,=,!=, and, or

src/analysis/raster/qgsrelief.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ GDALDatasetH QgsRelief::openInputFile( int& nCellsX, int& nCellsY )
427427

428428
GDALDriverH QgsRelief::openOutputDriver()
429429
{
430-
char **driverMetadata;
430+
char **driverMetadata = nullptr;
431431

432432
//open driver
433433
GDALDriverH outputDriver = GDALGetDriverByName( mOutputFormat.toLocal8Bit().data() );

src/analysis/raster/qgsrelief.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ class ANALYSIS_EXPORT QgsRelief
8686

8787
double mZFactor;
8888

89-
QgsSlopeFilter* mSlopeFilter;
90-
QgsAspectFilter* mAspectFilter;
91-
QgsHillshadeFilter* mHillshadeFilter285;
92-
QgsHillshadeFilter* mHillshadeFilter300;
93-
QgsHillshadeFilter* mHillshadeFilter315;
89+
QgsSlopeFilter* mSlopeFilter = nullptr;
90+
QgsAspectFilter* mAspectFilter = nullptr;
91+
QgsHillshadeFilter* mHillshadeFilter285 = nullptr;
92+
QgsHillshadeFilter* mHillshadeFilter300 = nullptr;
93+
QgsHillshadeFilter* mHillshadeFilter315 = nullptr;
9494

9595
//relief colors and corresponding elevations
9696
QList< ReliefColor > mReliefColors;

0 commit comments

Comments
 (0)