always NUL-terminate log messages, even if they're longer than buffer size
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21157 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -119,13 +119,24 @@ static inline bool IsLoggingEnabled()
|
|||||||
// macros and not all compilers inline vararg functions.
|
// macros and not all compilers inline vararg functions.
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// wrapper for wxVsnprintf(s_szBuf) which always NULL-terminates it
|
||||||
|
static inline void PrintfInLogBug(const wxChar *szFormat, va_list argptr)
|
||||||
|
{
|
||||||
|
if ( wxVsnprintf(s_szBuf, s_szBufSize, szFormat, argptr) < 0 )
|
||||||
|
{
|
||||||
|
// must NUL-terminate it manually
|
||||||
|
s_szBuf[s_szBufSize - 1] = _T('\0');
|
||||||
|
}
|
||||||
|
//else: NUL-terminated by vsnprintf()
|
||||||
|
}
|
||||||
|
|
||||||
// generic log function
|
// generic log function
|
||||||
void wxVLogGeneric(wxLogLevel level, const wxChar *szFormat, va_list argptr)
|
void wxVLogGeneric(wxLogLevel level, const wxChar *szFormat, va_list argptr)
|
||||||
{
|
{
|
||||||
if ( IsLoggingEnabled() ) {
|
if ( IsLoggingEnabled() ) {
|
||||||
wxCRIT_SECT_LOCKER(locker, gs_csLogBuf);
|
wxCRIT_SECT_LOCKER(locker, gs_csLogBuf);
|
||||||
|
|
||||||
wxVsnprintf(s_szBuf, s_szBufSize, szFormat, argptr);
|
PrintfInLogBug(szFormat, argptr);
|
||||||
|
|
||||||
wxLog::OnLog(level, s_szBuf, time(NULL));
|
wxLog::OnLog(level, s_szBuf, time(NULL));
|
||||||
}
|
}
|
||||||
@@ -145,11 +156,12 @@ void wxLogGeneric(wxLogLevel level, const wxChar *szFormat, ...)
|
|||||||
if ( IsLoggingEnabled() ) { \
|
if ( IsLoggingEnabled() ) { \
|
||||||
wxCRIT_SECT_LOCKER(locker, gs_csLogBuf); \
|
wxCRIT_SECT_LOCKER(locker, gs_csLogBuf); \
|
||||||
\
|
\
|
||||||
wxVsnprintf(s_szBuf, s_szBufSize, szFormat, argptr); \
|
PrintfInLogBug(szFormat, argptr); \
|
||||||
\
|
\
|
||||||
wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
|
wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
void wxLog##level(const wxChar *szFormat, ...) \
|
void wxLog##level(const wxChar *szFormat, ...) \
|
||||||
{ \
|
{ \
|
||||||
va_list argptr; \
|
va_list argptr; \
|
||||||
|
Reference in New Issue
Block a user