X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5e52e0297dee5888997da433f9ee52864dea905c..a2d6d210991fb1d29570a46e0f26c7a4b9cf89ff:/src/common/wxchar.cpp diff --git a/src/common/wxchar.cpp b/src/common/wxchar.cpp index 8f806d62fa..10bcd27cb4 100644 --- a/src/common/wxchar.cpp +++ b/src/common/wxchar.cpp @@ -196,8 +196,7 @@ bool WXDLLEXPORT wxOKlibc() // implemented later in this file using wxVsnprintf() and that would // result in an endless recursion and thus in a stack overflow #if wxUSE_UNICODE - - #if defined(__WINDOWS__) + #if defined(__WINDOWS__) && !defined(HAVE_SWPRINTF) // all compilers under Windows should have swprintf() #define HAVE_SWPRINTF #endif @@ -210,20 +209,21 @@ bool WXDLLEXPORT wxOKlibc() (defined(__VISUALC__) && __VISUALC__ < 1400) || \ defined(__GNUWIN32__) || \ defined(__BORLANDC__) - #define HAVE_BROKEN_SWPRINTF_DECL + #ifndef HAVE_BROKEN_SWPRINTF_DECL + #define HAVE_BROKEN_SWPRINTF_DECL + #endif #endif - - // problem: on some systems swprintf takes the 'max' argument while on others - // it doesn't + // problem: on some systems swprintf takes the 'max' argument while on + // others it doesn't #if defined(HAVE_BROKEN_SWPRINTF_DECL) - - // like when using sprintf(), since 'max' is not used, wxVsnprintf() should - // always ensure that 'buff' is big enough for all common needs + // like when using sprintf(), since 'max' is not used, wxVsnprintf() + // should always ensure that 'buff' is big enough for all common needs #define system_sprintf(buff, max, flags, data) \ ::swprintf(buff, flags, data) - #else + #define SYSTEM_SPRINTF_IS_UNSAFE + #else #if !defined(HAVE_SWPRINTF) #error wxVsnprintf() needs a system swprintf() implementation! #endif @@ -231,24 +231,24 @@ bool WXDLLEXPORT wxOKlibc() #define system_sprintf(buff, max, flags, data) \ ::swprintf(buff, max, flags, data) #endif - -#else - - #if defined(HAVE_SNPRINTF) - +#else // !wxUSE_UNICODE + #if defined(__VISUALC__) || \ + (defined(__BORLANDC__) && __BORLANDC__ >= 0x540) + #define system_sprintf(buff, max, flags, data) \ + ::_snprintf(buff, max, flags, data) + #elif defined(HAVE_SNPRINTF) #define system_sprintf(buff, max, flags, data) \ ::snprintf(buff, max, flags, data) - - #else // NB: at least sprintf() should *always* be available - - // since 'max' is not used in this case, wxVsnprintf() should always ensure - // that 'buff' is big enough for all common needs + #else // NB: at least sprintf() should always be available + // since 'max' is not used in this case, wxVsnprintf() should always + // ensure that 'buff' is big enough for all common needs // (see wxMAX_SVNPRINTF_FLAGBUFFER_LEN and wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN) #define system_sprintf(buff, max, flags, data) \ ::sprintf(buff, flags, data) + #define SYSTEM_SPRINTF_IS_UNSAFE #endif -#endif +#endif // wxUSE_UNICODE/!wxUSE_UNICODE @@ -580,6 +580,8 @@ bool wxPrintfConvSpec::Parse(const wxChar *format) case wxT('p'): m_type = wxPAT_POINTER; + m_szFlags[flagofs++] = ch; + m_szFlags[flagofs] = '\0'; done = true; break; @@ -678,12 +680,11 @@ void wxPrintfConvSpec::ReplaceAsteriskWith(int width) } // replace * with the actual integer given as width - int maxlen = (m_szFlags + wxMAX_SVNPRINTF_FLAGBUFFER_LEN - pwidth) / sizeof(wxChar); - int offset = system_sprintf(pwidth, maxlen, wxT("%d"), abs(width)); - -#ifdef HAVE_BROKEN_SWPRINTF_DECL - wxUnusedVar(maxlen); // avoid dummy warnings +#ifndef SYSTEM_SPRINTF_IS_UNSAFE + int maxlen = (m_szFlags + wxMAX_SVNPRINTF_FLAGBUFFER_LEN - pwidth) / + sizeof(wxChar); #endif + int offset = system_sprintf(pwidth, maxlen, wxT("%d"), abs(width)); // restore after the expanded * what was following it wxStrcpy(pwidth+offset, temp); @@ -985,7 +986,7 @@ int wxPrintfConvSpec::Process(wxChar *buf, size_t lenMax, wxPrintfArg *p) case wxPAT_POINTER: #if wxUSE_STRUTILS { - wxASSERT(lenScratch >= 0 && lenScratch < wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN); + wxASSERT( /* lenScratch >= 0 && */ lenScratch < wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN); if (lenMax < lenScratch) { // fill output buffer and then return -1