mirror of https://github.com/axmolengine/axmol.git
Added CC_FORMAT_PRINTF(x,y) macro to warn on CCLog() format errors
Uses printf format. Enabled for GCC and clang.
This commit is contained in:
parent
fd0e4a80df
commit
e5b2f300f9
|
@ -40,7 +40,7 @@ static const int kMaxLogLen = 16*1024;
|
||||||
/**
|
/**
|
||||||
@brief Output Debug message.
|
@brief Output Debug message.
|
||||||
*/
|
*/
|
||||||
void CC_DLL CCLog(const char * pszFormat, ...);
|
void CC_DLL CCLog(const char * pszFormat, ...) CC_FORMAT_PRINTF(1, 2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lua can not deal with ...
|
* lua can not deal with ...
|
||||||
|
|
|
@ -244,6 +244,21 @@ public: virtual void set##funName(varType var) \
|
||||||
#define CC_DEPRECATED_ATTRIBUTE
|
#define CC_DEPRECATED_ATTRIBUTE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* only certain compiler support __attribute__((format))
|
||||||
|
* formatPos - 1-based position of format string argument
|
||||||
|
* argPos - 1-based position of first format-dependent argument
|
||||||
|
*/
|
||||||
|
#if defined(__GNUC__) && (__GNUC__ >= 4)
|
||||||
|
#define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos)))
|
||||||
|
#elif defined(__has_attribute)
|
||||||
|
#if __has_attribute(format)
|
||||||
|
#define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos)))
|
||||||
|
#endif // __has_attribute(format)
|
||||||
|
#else
|
||||||
|
#define CC_FORMAT_PRINTF(formatPos, argPos)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define CC_UNUSED __attribute__ ((unused))
|
#define CC_UNUSED __attribute__ ((unused))
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -51,7 +51,7 @@ void CCLog(const char * pszFormat, ...)
|
||||||
void CCMessageBox(const char * pszMsg, const char * pszTitle)
|
void CCMessageBox(const char * pszMsg, const char * pszTitle)
|
||||||
{
|
{
|
||||||
//MessageBoxA(NULL, pszMsg, pszTitle, MB_OK);
|
//MessageBoxA(NULL, pszMsg, pszTitle, MB_OK);
|
||||||
CCLog(pszMsg);
|
CCLog("%s", pszMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCLuaLog(const char * pszFormat)
|
void CCLuaLog(const char * pszFormat)
|
||||||
|
|
|
@ -56,7 +56,7 @@ void CCMessageBox(const char * pszMsg, const char * pszTitle)
|
||||||
|
|
||||||
void CCLuaLog(const char * pszFormat)
|
void CCLuaLog(const char * pszFormat)
|
||||||
{
|
{
|
||||||
CCLog(pszFormat);
|
CCLog("%s", pszFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -85,7 +85,7 @@ void CCProfiler::displayTimers()
|
||||||
CCDICT_FOREACH(m_pActiveTimers, pElement)
|
CCDICT_FOREACH(m_pActiveTimers, pElement)
|
||||||
{
|
{
|
||||||
CCProfilingTimer* timer = (CCProfilingTimer*)pElement->getObject();
|
CCProfilingTimer* timer = (CCProfilingTimer*)pElement->getObject();
|
||||||
CCLog(timer->description());
|
CCLog("%s", timer->description());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1931,7 +1931,7 @@ void Issue1398::onEnter()
|
||||||
void Issue1398::incrementIntegerCallback(CCNode* pSender, void* data)
|
void Issue1398::incrementIntegerCallback(CCNode* pSender, void* data)
|
||||||
{
|
{
|
||||||
this->incrementInteger();
|
this->incrementInteger();
|
||||||
CCLog((char*)data);
|
CCLog("%s", (char*)data);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Issue1398::subtitle()
|
std::string Issue1398::subtitle()
|
||||||
|
|
|
@ -658,7 +658,8 @@ TestNode::~TestNode()
|
||||||
|
|
||||||
void TestNode::update(float dt)
|
void TestNode::update(float dt)
|
||||||
{
|
{
|
||||||
CCLog(m_pstring->getCString());
|
CC_UNUSED_PARAM(dt);
|
||||||
|
CCLog("%s", m_pstring->getCString());
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue