Permalink
Browse files

fix different problems founded by static analize

  • Loading branch information...
newnon committed Aug 1, 2017
1 parent 50db8bf commit 546958ca4224cd4b47d464e732a2fada6bc14123
View
@@ -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)
{
@@ -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
@@ -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();
@@ -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
@@ -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
@@ -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;
}
@@ -376,6 +376,9 @@ void AudioEngine::stopAll()
void AudioEngine::uncache(const std::string &filePath)
{
if(!_audioEngineImpl){
return;
}
auto audioIDsIter = _audioPathIDMap.find(filePath);
if (audioIDsIter != _audioPathIDMap.end())
{
View
@@ -331,7 +331,8 @@ void Director::drawScene()
_renderer->clearDrawStats();
//render the scene
_openGLView->renderScene(_runningScene, _renderer);
if(_openGLView)
_openGLView->renderScene(_runningScene, _renderer);
_eventDispatcher->dispatchEvent(_eventAfterVisit);
}
@@ -1061,7 +1062,8 @@ void Director::reset()
_runningScene = nullptr;
_nextScene = nullptr;
_eventDispatcher->dispatchEvent(_eventResetDirector);
if (_eventDispatcher)
_eventDispatcher->dispatchEvent(_eventResetDirector);
// cleanup scheduler
getScheduler()->unscheduleAll();
@@ -1368,8 +1370,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;
}
@@ -437,10 +437,11 @@ void Scheduler::priorityIn(tListEntry **list, const ccSchedulerFunc& callback, v
}
// update hash entry for quick access
tHashUpdateEntry *hashElement = (tHashUpdateEntry *)calloc(sizeof(*hashElement), 1);
tHashUpdateEntry *hashElement = new (std::nothrow) tHashUpdateEntry;
hashElement->target = target;
hashElement->list = list;
hashElement->entry = listElement;
memset(&hashElement->hh, 0, sizeof(hashElement->hh));
HASH_ADD_PTR(_hashForUpdates, target, hashElement);
}
@@ -457,10 +458,11 @@ void Scheduler::appendIn(_listEntry **list, const ccSchedulerFunc& callback, voi
DL_APPEND(*list, listElement);
// update hash entry for quicker access
tHashUpdateEntry *hashElement = (tHashUpdateEntry *)calloc(sizeof(*hashElement), 1);
tHashUpdateEntry *hashElement = new (std::nothrow) tHashUpdateEntry;
hashElement->target = target;
hashElement->list = list;
hashElement->entry = listElement;
memset(&hashElement->hh, 0, sizeof(hashElement->hh));
HASH_ADD_PTR(_hashForUpdates, target, hashElement);
}
@@ -474,22 +474,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;
}
@@ -375,12 +375,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);
@@ -415,12 +415,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);

0 comments on commit 546958c

Please sign in to comment.