V3 static analize fixes (#18638)

* fix different problems founded by static analize

* fix bad render assert

* Fix misprint

* reverted calloc in CCScheduler
This commit is contained in:
newnon 2018-01-19 08:40:41 +03:00 committed by minggo
parent 27a1312d1e
commit 2ff42bb38e
13 changed files with 32 additions and 28 deletions

View File

@ -200,7 +200,8 @@ Follow* Follow::createWithOffset(Node* followedNode,float xOffset,float yOffset,
bool valid;
valid = follow->initWithTargetAndOffset(followedNode, xOffset, yOffset,rect);
if(follow)
valid = follow->initWithTargetAndOffset(followedNode, xOffset, yOffset,rect);
if (follow && valid)
{

View File

@ -445,9 +445,7 @@ Repeat* Repeat::create(FiniteTimeAction *action, unsigned int times)
bool Repeat::initWithAction(FiniteTimeAction *action, unsigned int times)
{
float d = action->getDuration() * times;
if (action && ActionInterval::initWithDuration(d))
if (action && ActionInterval::initWithDuration(action->getDuration() * times))
{
_times = times;
_innerAction = action;

View File

@ -86,13 +86,14 @@ bool AtlasNode::initWithTexture(Texture2D* texture, int tileWidth, int tileHeigh
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
_textureAtlas = new (std::nothrow) TextureAtlas();
_textureAtlas->initWithTexture(texture, itemsToRender);
if (! _textureAtlas)
{
CCLOG("cocos2d: Could not initialize AtlasNode. Invalid Texture.");
return false;
}
_textureAtlas->initWithTexture(texture, itemsToRender);
this->updateBlendFunc();
this->updateOpacityModifyRGB();

View File

@ -227,7 +227,7 @@ void drawCircle( const Vec2& center, float radius, float angle, unsigned int seg
const float coef = 2.0f * (float)M_PI/segments;
GLfloat *vertices = (GLfloat*)calloc( sizeof(GLfloat)*2*(segments+2), 1);
GLfloat *vertices = (GLfloat*)calloc( 2*(segments+2), sizeof(GLfloat));
if( ! vertices )
return;
@ -267,7 +267,7 @@ void drawSolidCircle( const Vec2& center, float radius, float angle, unsigned in
const float coef = 2.0f * (float)M_PI/segments;
GLfloat *vertices = (GLfloat*)calloc( sizeof(GLfloat)*2*(segments+2), 1);
GLfloat *vertices = (GLfloat*)calloc( 2*(segments+2), sizeof(GLfloat));
if( ! vertices )
return;

View File

@ -105,16 +105,17 @@ bool GridBase::initWithSize(const cocos2d::Size &gridSize, const cocos2d::Rect &
}
Texture2D *texture = new (std::nothrow) Texture2D();
texture->initWithData(data, dataLen, format, POTWide, POTHigh, s);
free(data);
if (! texture)
{
free(data);
CCLOG("cocos2d: Grid: error creating texture");
return false;
}
texture->initWithData(data, dataLen, format, POTWide, POTHigh, s);
free(data);
initWithSize(gridSize, texture, false, rect);
texture->release();

View File

@ -226,7 +226,7 @@ void LabelTTF::setTextDefinition(const FontDefinition& theDefinition)
const FontDefinition& LabelTTF::getTextDefinition()
{
auto fontDef = _renderLabel->getFontDefinition();
memcpy(&_fontDef, &fontDef, sizeof(FontDefinition));
_fontDef = fontDef;
return _fontDef;
}

View File

@ -371,6 +371,9 @@ void AudioEngine::stopAll()
void AudioEngine::uncache(const std::string &filePath)
{
if(!_audioEngineImpl){
return;
}
auto audioIDsIter = _audioPathIDMap.find(filePath);
if (audioIDsIter != _audioPathIDMap.end())
{

View File

@ -325,7 +325,8 @@ void Director::drawScene()
_renderer->clearDrawStats();
//render the scene
_openGLView->renderScene(_runningScene, _renderer);
if(_openGLView)
_openGLView->renderScene(_runningScene, _renderer);
_eventDispatcher->dispatchEvent(_eventAfterVisit);
}
@ -1065,7 +1066,8 @@ void Director::reset()
_runningScene = nullptr;
_nextScene = nullptr;
_eventDispatcher->dispatchEvent(_eventResetDirector);
if (_eventDispatcher)
_eventDispatcher->dispatchEvent(_eventResetDirector);
// cleanup scheduler
getScheduler()->unscheduleAll();
@ -1372,8 +1374,10 @@ void Director::createStatsLabel()
getFPSImageData(&data, &dataLength);
Image* image = new (std::nothrow) Image();
bool isOK = image->initWithImageData(data, dataLength);
bool isOK = image ? image->initWithImageData(data, dataLength) : false;
if (! isOK) {
if(image)
delete image;
CCLOGERROR("%s", "Fails: init fps_images");
return;
}

View File

@ -441,6 +441,7 @@ void Scheduler::priorityIn(tListEntry **list, const ccSchedulerFunc& callback, v
hashElement->target = target;
hashElement->list = list;
hashElement->entry = listElement;
memset(&hashElement->hh, 0, sizeof(hashElement->hh));
HASH_ADD_PTR(_hashForUpdates, target, hashElement);
}
@ -461,6 +462,7 @@ void Scheduler::appendIn(_listEntry **list, const ccSchedulerFunc& callback, voi
hashElement->target = target;
hashElement->list = list;
hashElement->entry = listElement;
memset(&hashElement->hh, 0, sizeof(hashElement->hh));
HASH_ADD_PTR(_hashForUpdates, target, hashElement);
}

View File

@ -490,22 +490,21 @@ bool UserDefault::createXMLFile()
}
tinyxml2::XMLDeclaration *pDeclaration = pDoc->NewDeclaration(nullptr);
if (nullptr==pDeclaration)
{
{
delete pDoc;
return false;
}
pDoc->LinkEndChild(pDeclaration);
tinyxml2::XMLElement *pRootEle = pDoc->NewElement(USERDEFAULT_ROOT_NAME);
if (nullptr==pRootEle)
{
{
delete pDoc;
return false;
}
pDoc->LinkEndChild(pRootEle);
bRet = tinyxml2::XML_SUCCESS == pDoc->SaveFile(FileUtils::getInstance()->getSuitableFOpen(_filePath).c_str());
if(pDoc)
{
delete pDoc;
}
delete pDoc;
return bRet;
}

View File

@ -376,12 +376,12 @@ bool FileUtils::writeValueMapToFile(const ValueMap& dict, const std::string& ful
doc->LinkEndChild(docType);
tinyxml2::XMLElement *rootEle = doc->NewElement("plist");
rootEle->SetAttribute("version", "1.0");
if (nullptr == rootEle)
{
delete doc;
return false;
}
rootEle->SetAttribute("version", "1.0");
doc->LinkEndChild(rootEle);
tinyxml2::XMLElement *innerDict = generateElementForDict(dict, doc);
@ -416,12 +416,12 @@ bool FileUtils::writeValueVectorToFile(const ValueVector& vecData, const std::st
doc->LinkEndChild(docType);
tinyxml2::XMLElement *rootEle = doc->NewElement("plist");
rootEle->SetAttribute("version", "1.0");
if (nullptr == rootEle)
{
delete doc;
return false;
}
rootEle->SetAttribute("version", "1.0");
doc->LinkEndChild(rootEle);
tinyxml2::XMLElement *innerDict = generateElementForArray(vecData, doc);

View File

@ -757,7 +757,7 @@ void Renderer::drawBatchedTriangles()
// in the same batch ?
if (batchable && (prevMaterialID == currentMaterialID || firstCommand))
{
CC_ASSERT(firstCommand || _triBatchesToDraw[batchesTotal].cmd->getMaterialID() == cmd->getMaterialID() && "argh... error in logic");
CC_ASSERT((firstCommand || _triBatchesToDraw[batchesTotal].cmd->getMaterialID() == cmd->getMaterialID()) && "argh... error in logic");
_triBatchesToDraw[batchesTotal].indicesToDraw += cmd->getIndexCount();
_triBatchesToDraw[batchesTotal].cmd = cmd;
}

View File

@ -94,11 +94,6 @@ bool PUMeshSurfaceEmitterTranslator::translateChildProperty( PUScriptCompiler* c
emitter->setDistribution(MeshInfo::MSD_HOMOGENEOUS);
return true;
}
else if (val == token[TOKEN_MESH_SURFACE_HOMOGENEOUS])
{
emitter->setDistribution(MeshInfo::MSD_HOMOGENEOUS);
return true;
}
}
}
}