mirror of https://github.com/axmolengine/axmol.git
issue #1166: Checked whether memory is allocated successfully in CCString::initWithFormatAndValist function.
This commit is contained in:
parent
be129913a8
commit
0af443a56f
|
@ -37,11 +37,16 @@ CCString& CCString::operator= (const CCString& other)
|
||||||
|
|
||||||
bool CCString::initWithFormatAndValist(const char* format, va_list ap)
|
bool CCString::initWithFormatAndValist(const char* format, va_list ap)
|
||||||
{
|
{
|
||||||
|
bool bRet = false;
|
||||||
char* pBuf = (char*)malloc(kMaxStringLen);
|
char* pBuf = (char*)malloc(kMaxStringLen);
|
||||||
vsnprintf(pBuf, kMaxStringLen, format, ap);
|
if (pBuf != NULL)
|
||||||
m_sString = pBuf;
|
{
|
||||||
free(pBuf);
|
vsnprintf(pBuf, kMaxStringLen, format, ap);
|
||||||
return true;
|
m_sString = pBuf;
|
||||||
|
free(pBuf);
|
||||||
|
bRet = true;
|
||||||
|
}
|
||||||
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCString::initWithFormat(const char* format, ...)
|
bool CCString::initWithFormat(const char* format, ...)
|
||||||
|
@ -152,13 +157,12 @@ CCString* CCString::stringWithData(unsigned char* pData, unsigned long nLen)
|
||||||
CCString* pRet = NULL;
|
CCString* pRet = NULL;
|
||||||
if (pData != NULL && nLen > 0)
|
if (pData != NULL && nLen > 0)
|
||||||
{
|
{
|
||||||
pRet = CCString::stringWithCString("");
|
|
||||||
char* pStr = (char*)malloc(nLen+1);
|
char* pStr = (char*)malloc(nLen+1);
|
||||||
if (pStr != NULL)
|
if (pStr != NULL)
|
||||||
{
|
{
|
||||||
pStr[nLen] = '\0';
|
pStr[nLen] = '\0';
|
||||||
memcpy(pStr, pData, nLen);
|
memcpy(pStr, pData, nLen);
|
||||||
pRet->m_sString = pStr;
|
pRet = CCString::stringWithCString(pStr);
|
||||||
free(pStr);
|
free(pStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue