Skip to content

Commit 2ff42bb

Browse files
newnonminggo
authored andcommitted
V3 static analize fixes (#18638)
* fix different problems founded by static analize * fix bad render assert * Fix misprint * reverted calloc in CCScheduler
1 parent 27a1312 commit 2ff42bb

File tree

13 files changed

+32
-28
lines changed

13 files changed

+32
-28
lines changed

cocos/2d/CCAction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ Follow* Follow::createWithOffset(Node* followedNode,float xOffset,float yOffset,
200200

201201
bool valid;
202202

203-
valid = follow->initWithTargetAndOffset(followedNode, xOffset, yOffset,rect);
203+
if(follow)
204+
valid = follow->initWithTargetAndOffset(followedNode, xOffset, yOffset,rect);
204205

205206
if (follow && valid)
206207
{

cocos/2d/CCActionInterval.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,7 @@ Repeat* Repeat::create(FiniteTimeAction *action, unsigned int times)
445445

446446
bool Repeat::initWithAction(FiniteTimeAction *action, unsigned int times)
447447
{
448-
float d = action->getDuration() * times;
449-
450-
if (action && ActionInterval::initWithDuration(d))
448+
if (action && ActionInterval::initWithDuration(action->getDuration() * times))
451449
{
452450
_times = times;
453451
_innerAction = action;

cocos/2d/CCAtlasNode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ bool AtlasNode::initWithTexture(Texture2D* texture, int tileWidth, int tileHeigh
8686
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
8787

8888
_textureAtlas = new (std::nothrow) TextureAtlas();
89-
_textureAtlas->initWithTexture(texture, itemsToRender);
9089

9190
if (! _textureAtlas)
9291
{
9392
CCLOG("cocos2d: Could not initialize AtlasNode. Invalid Texture.");
9493
return false;
9594
}
95+
96+
_textureAtlas->initWithTexture(texture, itemsToRender);
9697

9798
this->updateBlendFunc();
9899
this->updateOpacityModifyRGB();

cocos/2d/CCDrawingPrimitives.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void drawCircle( const Vec2& center, float radius, float angle, unsigned int seg
227227

228228
const float coef = 2.0f * (float)M_PI/segments;
229229

230-
GLfloat *vertices = (GLfloat*)calloc( sizeof(GLfloat)*2*(segments+2), 1);
230+
GLfloat *vertices = (GLfloat*)calloc( 2*(segments+2), sizeof(GLfloat));
231231
if( ! vertices )
232232
return;
233233

@@ -267,7 +267,7 @@ void drawSolidCircle( const Vec2& center, float radius, float angle, unsigned in
267267

268268
const float coef = 2.0f * (float)M_PI/segments;
269269

270-
GLfloat *vertices = (GLfloat*)calloc( sizeof(GLfloat)*2*(segments+2), 1);
270+
GLfloat *vertices = (GLfloat*)calloc( 2*(segments+2), sizeof(GLfloat));
271271
if( ! vertices )
272272
return;
273273

cocos/2d/CCGrid.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,17 @@ bool GridBase::initWithSize(const cocos2d::Size &gridSize, const cocos2d::Rect &
105105
}
106106

107107
Texture2D *texture = new (std::nothrow) Texture2D();
108-
texture->initWithData(data, dataLen, format, POTWide, POTHigh, s);
109-
110-
free(data);
111108

112109
if (! texture)
113110
{
111+
free(data);
114112
CCLOG("cocos2d: Grid: error creating texture");
115113
return false;
116114
}
117115

116+
texture->initWithData(data, dataLen, format, POTWide, POTHigh, s);
117+
free(data);
118+
118119
initWithSize(gridSize, texture, false, rect);
119120

120121
texture->release();

cocos/2d/CCLabelTTF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void LabelTTF::setTextDefinition(const FontDefinition& theDefinition)
226226
const FontDefinition& LabelTTF::getTextDefinition()
227227
{
228228
auto fontDef = _renderLabel->getFontDefinition();
229-
memcpy(&_fontDef, &fontDef, sizeof(FontDefinition));
229+
_fontDef = fontDef;
230230
return _fontDef;
231231
}
232232

cocos/audio/AudioEngine.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ void AudioEngine::stopAll()
371371

372372
void AudioEngine::uncache(const std::string &filePath)
373373
{
374+
if(!_audioEngineImpl){
375+
return;
376+
}
374377
auto audioIDsIter = _audioPathIDMap.find(filePath);
375378
if (audioIDsIter != _audioPathIDMap.end())
376379
{

cocos/base/CCDirector.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ void Director::drawScene()
325325
_renderer->clearDrawStats();
326326

327327
//render the scene
328-
_openGLView->renderScene(_runningScene, _renderer);
328+
if(_openGLView)
329+
_openGLView->renderScene(_runningScene, _renderer);
329330

330331
_eventDispatcher->dispatchEvent(_eventAfterVisit);
331332
}
@@ -1065,7 +1066,8 @@ void Director::reset()
10651066
_runningScene = nullptr;
10661067
_nextScene = nullptr;
10671068

1068-
_eventDispatcher->dispatchEvent(_eventResetDirector);
1069+
if (_eventDispatcher)
1070+
_eventDispatcher->dispatchEvent(_eventResetDirector);
10691071

10701072
// cleanup scheduler
10711073
getScheduler()->unscheduleAll();
@@ -1372,8 +1374,10 @@ void Director::createStatsLabel()
13721374
getFPSImageData(&data, &dataLength);
13731375

13741376
Image* image = new (std::nothrow) Image();
1375-
bool isOK = image->initWithImageData(data, dataLength);
1377+
bool isOK = image ? image->initWithImageData(data, dataLength) : false;
13761378
if (! isOK) {
1379+
if(image)
1380+
delete image;
13771381
CCLOGERROR("%s", "Fails: init fps_images");
13781382
return;
13791383
}

cocos/base/CCScheduler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ void Scheduler::priorityIn(tListEntry **list, const ccSchedulerFunc& callback, v
441441
hashElement->target = target;
442442
hashElement->list = list;
443443
hashElement->entry = listElement;
444+
memset(&hashElement->hh, 0, sizeof(hashElement->hh));
444445
HASH_ADD_PTR(_hashForUpdates, target, hashElement);
445446
}
446447

@@ -461,6 +462,7 @@ void Scheduler::appendIn(_listEntry **list, const ccSchedulerFunc& callback, voi
461462
hashElement->target = target;
462463
hashElement->list = list;
463464
hashElement->entry = listElement;
465+
memset(&hashElement->hh, 0, sizeof(hashElement->hh));
464466
HASH_ADD_PTR(_hashForUpdates, target, hashElement);
465467
}
466468

cocos/base/CCUserDefault.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,22 +490,21 @@ bool UserDefault::createXMLFile()
490490
}
491491
tinyxml2::XMLDeclaration *pDeclaration = pDoc->NewDeclaration(nullptr);
492492
if (nullptr==pDeclaration)
493-
{
493+
{
494+
delete pDoc;
494495
return false;
495496
}
496497
pDoc->LinkEndChild(pDeclaration);
497498
tinyxml2::XMLElement *pRootEle = pDoc->NewElement(USERDEFAULT_ROOT_NAME);
498499
if (nullptr==pRootEle)
499-
{
500+
{
501+
delete pDoc;
500502
return false;
501503
}
502504
pDoc->LinkEndChild(pRootEle);
503505
bRet = tinyxml2::XML_SUCCESS == pDoc->SaveFile(FileUtils::getInstance()->getSuitableFOpen(_filePath).c_str());
504506

505-
if(pDoc)
506-
{
507-
delete pDoc;
508-
}
507+
delete pDoc;
509508

510509
return bRet;
511510
}

0 commit comments

Comments
 (0)