]> git.saurik.com Git - wxWidgets.git/commitdiff
always NUL-terminate log messages, even if they're longer than buffer size
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 14 Jun 2003 16:45:31 +0000 (16:45 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 14 Jun 2003 16:45:31 +0000 (16:45 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21157 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/log.cpp

index 02b83693bfc8bbc3f2dfc6ed0fdff2b76a8b616d..06b2283ad42e98bedc6238e301dfd558ce48e4bb 100644 (file)
@@ -119,13 +119,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));
     }
@@ -145,11 +156,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;                                                 \