Skip to content

Commit e9f5bb6

Browse files
JohnCoconuthuangwei1024
authored andcommitted
add new clang-tidy option (cocos2d#19682)
* add new clang-tidy option * readability-delete-null-pointer * more fix for readability-delete-null-pointer
1 parent c34b3bd commit e9f5bb6

File tree

11 files changed

+42
-81
lines changed

11 files changed

+42
-81
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Checks: >
99
performance-move-const-arg,
1010
performance-type-promotion-in-math-fn,
1111
readability-container-size-empty,
12+
readability-delete-null-pointer,
1213
1314
WarningsAsErrors: '*'
1415
HeaderFilterRegex: '/(?!external)/.*'

cocos/2d/CCFontAtlas.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,7 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)
433433
tempDef.V = tempDef.V / scaleFactor;
434434
}
435435
else{
436-
if(bitmap)
437-
delete[] bitmap;
436+
delete[] bitmap;
438437
if (tempDef.xAdvance)
439438
tempDef.validDefinition = true;
440439
else

cocos/3d/CCTerrain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,10 +1583,10 @@ void Terrain::QuadTree::preCalculateAABB(const Mat4 & worldTransform)
15831583

15841584
Terrain::QuadTree::~QuadTree()
15851585
{
1586-
if(_tl) delete _tl;
1587-
if(_tr) delete _tr;
1588-
if(_bl) delete _bl;
1589-
if(_br) delete _br;
1586+
delete _tl;
1587+
delete _tr;
1588+
delete _bl;
1589+
delete _br;
15901590
}
15911591

15921592
Terrain::TerrainData::TerrainData(const std::string& heightMapsrc , const std::string& textureSrc, const Size & chunksize, float height, float scale)

cocos/base/CCDirector.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,7 @@ void Director::createStatsLabel()
13431343
Image* image = new (std::nothrow) Image();
13441344
bool isOK = image ? image->initWithImageData(data, dataLength) : false;
13451345
if (! isOK) {
1346-
if(image)
1347-
delete image;
1346+
delete image;
13481347
CCLOGERROR("%s", "Fails: init fps_images");
13491348
return;
13501349
}

cocos/base/CCUserDefault.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ bool UserDefault::getBoolForKey(const char* pKey, bool defaultValue)
195195
ret = (! strcmp(value, "true"));
196196
}
197197

198-
if (doc) delete doc;
198+
delete doc;
199199

200200
return ret;
201201
}
@@ -225,10 +225,7 @@ int UserDefault::getIntegerForKey(const char* pKey, int defaultValue)
225225
ret = atoi(value);
226226
}
227227

228-
if(doc)
229-
{
230-
delete doc;
231-
}
228+
delete doc;
232229

233230

234231
return ret;
@@ -271,7 +268,7 @@ double UserDefault::getDoubleForKey(const char* pKey, double defaultValue)
271268
ret = utils::atof(value);
272269
}
273270

274-
if (doc) delete doc;
271+
delete doc;
275272

276273
return ret;
277274
}
@@ -301,7 +298,7 @@ string UserDefault::getStringForKey(const char* pKey, const std::string & defaul
301298
ret = string(value);
302299
}
303300

304-
if (doc) delete doc;
301+
delete doc;
305302

306303
return ret;
307304
}
@@ -336,7 +333,7 @@ Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue)
336333
}
337334
}
338335

339-
if (doc) delete doc;
336+
delete doc;
340337

341338
return ret;
342339
}
@@ -447,8 +444,7 @@ void UserDefault::destroyInstance()
447444

448445
void UserDefault::setDelegate(UserDefault *delegate)
449446
{
450-
if (_userDefault)
451-
delete _userDefault;
447+
delete _userDefault;
452448

453449
_userDefault = delegate;
454450
}

cocos/base/ZipUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ ZipFile *ZipFile::createWithBuffer(const void* buffer, uLong size)
523523
if (zip && zip->initWithBuffer(buffer, size)) {
524524
return zip;
525525
} else {
526-
if (zip) delete zip;
526+
delete zip;
527527
return nullptr;
528528
}
529529
}

cocos/platform/CCFileUtils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,7 @@ void FileUtils::destroyInstance()
547547

548548
void FileUtils::setDelegate(FileUtils *delegate)
549549
{
550-
if (s_sharedFileUtils)
551-
delete s_sharedFileUtils;
550+
delete s_sharedFileUtils;
552551

553552
s_sharedFileUtils = delegate;
554553
}

cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5608,8 +5608,7 @@ void js_cocos2d_PolygonInfo_finalize(JSFreeOp *fop, JSObject *obj) {
56085608
if (proxy)
56095609
{
56105610
cocos2d::PolygonInfo *nobj = static_cast<cocos2d::PolygonInfo *>(proxy->ptr);
5611-
if (nobj)
5612-
delete nobj;
5611+
delete nobj;
56135612
jsb_remove_proxy(proxy);
56145613
}
56155614
}
@@ -5766,8 +5765,7 @@ void js_cocos2d_AutoPolygon_finalize(JSFreeOp *fop, JSObject *obj) {
57665765
auto proxy = jsb_get_js_proxy(jsobj);
57675766
if (proxy) {
57685767
cocos2d::AutoPolygon *nobj = static_cast<cocos2d::AutoPolygon *>(proxy->ptr);
5769-
if (nobj)
5770-
delete nobj;
5768+
delete nobj;
57715769
jsb_remove_proxy(proxy);
57725770
}
57735771
}

cocos/scripting/js-bindings/manual/component/CCComponentJS.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ ComponentJS::~ComponentJS()
104104
jsb_remove_proxy(proxy);
105105
}
106106
// Delete rooted object
107-
if (jsObj != nullptr)
108-
{
109-
delete jsObj;
110-
}
107+
delete jsObj;
111108
}
112109

113110
void* ComponentJS::getScriptObject() const

extensions/Particle3D/PU/CCPUEmitter.cpp

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -131,41 +131,30 @@ PUEmitter::~PUEmitter()
131131
{
132132
_particleSystem = nullptr;
133133

134-
if (_dynEmissionRate)
135-
delete _dynEmissionRate;
134+
delete _dynEmissionRate;
136135

137-
if (_dynTotalTimeToLive)
138-
delete _dynTotalTimeToLive;
136+
delete _dynTotalTimeToLive;
139137

140-
if (_dynParticleMass)
141-
delete _dynParticleMass;
138+
delete _dynParticleMass;
142139

143-
if (_dynVelocity)
144-
delete _dynVelocity;
140+
delete _dynVelocity;
145141

146-
if (_dynDuration)
147-
delete _dynDuration;
142+
delete _dynDuration;
148143

149-
if (_dynRepeatDelay)
150-
delete _dynRepeatDelay;
144+
delete _dynRepeatDelay;
151145

152-
if (_dynParticleAllDimensions)
153-
delete _dynParticleAllDimensions;
146+
delete _dynParticleAllDimensions;
154147

155-
if (_dynParticleWidth)
156-
delete _dynParticleWidth;
148+
delete _dynParticleWidth;
157149

158-
if (_dynParticleHeight)
159-
delete _dynParticleHeight;
150+
delete _dynParticleHeight;
160151

161-
if (_dynParticleDepth)
162-
delete _dynParticleDepth;
152+
delete _dynParticleDepth;
163153

164154
//if (mEmissionRateCameraDependency)
165155
// mCameraDependencyFactory.destroy(mEmissionRateCameraDependency);
166156

167-
if (_dynAngle)
168-
delete _dynAngle;
157+
delete _dynAngle;
169158
}
170159

171160
void PUEmitter::updateEmitter(Particle3D* /*particle*/, float /*deltaTime*/)
@@ -516,48 +505,42 @@ void PUEmitter::setEmitsName(const std::string& emitsName)
516505
//-----------------------------------------------------------------------
517506
void PUEmitter::setDynEmissionRate(PUDynamicAttribute* dynEmissionRate)
518507
{
519-
if (_dynEmissionRate)
520-
delete _dynEmissionRate;
508+
delete _dynEmissionRate;
521509

522510
_dynEmissionRate = dynEmissionRate;
523511
}
524512
//-----------------------------------------------------------------------
525513
void PUEmitter::setDynTotalTimeToLive(PUDynamicAttribute* dynTotalTimeToLive)
526514
{
527-
if (_dynTotalTimeToLive)
528-
delete _dynTotalTimeToLive;
515+
delete _dynTotalTimeToLive;
529516

530517
_dynTotalTimeToLive = dynTotalTimeToLive;
531518
}
532519
//-----------------------------------------------------------------------
533520
void PUEmitter::setDynParticleMass(PUDynamicAttribute* dynParticleMass)
534521
{
535-
if (_dynParticleMass)
536-
delete _dynParticleMass;
522+
delete _dynParticleMass;
537523

538524
_dynParticleMass = dynParticleMass;
539525
}
540526
//-----------------------------------------------------------------------
541527
void PUEmitter::setDynAngle(PUDynamicAttribute* dynAngle)
542528
{
543-
if (_dynAngle)
544-
delete _dynAngle;
529+
delete _dynAngle;
545530

546531
_dynAngle = dynAngle;
547532
}
548533
//-----------------------------------------------------------------------
549534
void PUEmitter::setDynVelocity(PUDynamicAttribute* dynVelocity)
550535
{
551-
if (_dynVelocity)
552-
delete _dynVelocity;
536+
delete _dynVelocity;
553537

554538
_dynVelocity = dynVelocity;
555539
}
556540
//-----------------------------------------------------------------------
557541
void PUEmitter::setDynDuration(PUDynamicAttribute* dynDuration)
558542
{
559-
if (_dynDuration)
560-
delete _dynDuration;
543+
delete _dynDuration;
561544

562545
_dynDuration = dynDuration;
563546
_dynDurationSet = true;
@@ -571,8 +554,7 @@ void PUEmitter::setDynDurationSet(bool durationSet)
571554
//-----------------------------------------------------------------------
572555
void PUEmitter::setDynRepeatDelay(PUDynamicAttribute* dynRepeatDelay)
573556
{
574-
if (_dynRepeatDelay)
575-
delete _dynRepeatDelay;
557+
delete _dynRepeatDelay;
576558

577559
_dynRepeatDelay = dynRepeatDelay;
578560
_dynRepeatDelaySet = true;
@@ -586,8 +568,7 @@ void PUEmitter::setDynRepeatDelaySet(bool repeatDelaySet)
586568
//-----------------------------------------------------------------------
587569
void PUEmitter::setDynParticleAllDimensions(PUDynamicAttribute* dynParticleAllDimensions)
588570
{
589-
if (_dynParticleAllDimensions)
590-
delete _dynParticleAllDimensions;
571+
delete _dynParticleAllDimensions;
591572

592573
_dynParticleAllDimensions = dynParticleAllDimensions;
593574
_dynParticleAllDimensionsSet = true;
@@ -600,8 +581,7 @@ void PUEmitter::setDynParticleAllDimensionsSet(bool particleAllDimensionsSet)
600581
//-----------------------------------------------------------------------
601582
void PUEmitter::setDynParticleWidth(PUDynamicAttribute* dynParticleWidth)
602583
{
603-
if (_dynParticleWidth)
604-
delete _dynParticleWidth;
584+
delete _dynParticleWidth;
605585

606586
_dynParticleWidth = dynParticleWidth;
607587
_dynParticleWidthSet = true;
@@ -614,8 +594,7 @@ void PUEmitter::setDynParticleWidthSet(bool particleWidthSet)
614594
//-----------------------------------------------------------------------
615595
void PUEmitter::setDynParticleHeight(PUDynamicAttribute* dynParticleHeight)
616596
{
617-
if (_dynParticleHeight)
618-
delete _dynParticleHeight;
597+
delete _dynParticleHeight;
619598

620599
_dynParticleHeight = dynParticleHeight;
621600
_dynParticleHeightSet = true;
@@ -628,8 +607,7 @@ void PUEmitter::setDynParticleHeightSet(bool particleHeightSet)
628607
//-----------------------------------------------------------------------
629608
void PUEmitter::setDynParticleDepth(PUDynamicAttribute* dynParticleDepth)
630609
{
631-
if (_dynParticleDepth)
632-
delete _dynParticleDepth;
610+
delete _dynParticleDepth;
633611

634612
_dynParticleDepth = dynParticleDepth;
635613
_dynParticleDepthSet = true;

0 commit comments

Comments
 (0)