always NUL-terminate log messages, even if they're longer than buffer size

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@21157 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-06-14 16:45:31 +00:00
parent 8d009f3f65
commit 412a5ab4ef
2 changed files with 20 additions and 2 deletions

View File

@@ -175,10 +175,16 @@ OTHER CHANGES
2.4.2
-----
wxBase:
- always NUL-terminate the log messages
All:
- wxRegEx::Compile() now calculates the number of groups correctly
2.4.1
-----

View File

@@ -114,13 +114,24 @@ static inline bool IsLoggingEnabled()
// 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
void wxVLogGeneric(wxLogLevel level, const wxChar *szFormat, va_list argptr)
{
if ( IsLoggingEnabled() ) {
wxCRIT_SECT_LOCKER(locker, gs_csLogBuf);
wxVsnprintf(s_szBuf, s_szBufSize, szFormat, argptr);
PrintfInLogBug(szFormat, argptr);
wxLog::OnLog(level, s_szBuf, time(NULL));
}
@@ -140,11 +151,12 @@ void wxLogGeneric(wxLogLevel level, const wxChar *szFormat, ...)
if ( IsLoggingEnabled() ) { \
wxCRIT_SECT_LOCKER(locker, gs_csLogBuf); \
\
wxVsnprintf(s_szBuf, s_szBufSize, szFormat, argptr); \
PrintfInLogBug(szFormat, argptr); \
\
wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
} \
} \
\
void wxLog##level(const wxChar *szFormat, ...) \
{ \
va_list argptr; \