From e68a8744eeba2381e6cfb3ba8a124f94a5978589 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Fri, 16 Jan 2009 12:07:47 +0000 Subject: [PATCH] silence gcc warnings in "vararg" functions such as wxPrintf when compiling with -Wformat-security git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58126 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/strvararg.h | 6 +++++- include/wx/wxcrtvararg.h | 22 ++++++++++++++-------- src/common/strvararg.cpp | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/include/wx/strvararg.h b/include/wx/strvararg.h index 4a9f0dbdd6..ed16e5ed90 100644 --- a/include/wx/strvararg.h +++ b/include/wx/strvararg.h @@ -154,11 +154,15 @@ public: // n-th variadic argument desired representation ArgumentType GetArgumentType(unsigned n) const; + // returns the value passed to ctor, only converted to wxString, similarly + // to other InputAsXXX() methods + wxString InputAsString() const; + #if !wxUSE_UNICODE_WCHAR operator const char*() const { return const_cast(this)->AsChar(); } private: - // InputAsChar() returns the value converted passed to ctor, only converted + // InputAsChar() returns the value passed to ctor, only converted // to char, while AsChar() takes the the string returned by InputAsChar() // and does format string conversion on it as well (and similarly for // ..AsWChar() below) diff --git a/include/wx/wxcrtvararg.h b/include/wx/wxcrtvararg.h index 77ffc5f0d7..1f6343c88d 100644 --- a/include/wx/wxcrtvararg.h +++ b/include/wx/wxcrtvararg.h @@ -281,10 +281,20 @@ #define wxCRT_FprintfNative wxCRT_FprintfA #endif -WX_DEFINE_VARARG_FUNC(int, wxPrintf, 1, (const wxFormatString&), - wxCRT_PrintfNative, wxCRT_PrintfA) -WX_DEFINE_VARARG_FUNC(int, wxFprintf, 2, (FILE*, const wxFormatString&), - wxCRT_FprintfNative, wxCRT_FprintfA) + +WX_DEFINE_VARARG_FUNC_SANS_N0(int, wxPrintf, 1, (const wxFormatString&), + wxCRT_PrintfNative, wxCRT_PrintfA) +inline int wxPrintf(const wxFormatString& s) +{ + return wxPrintf("%s", s.InputAsString()); +} + +WX_DEFINE_VARARG_FUNC_SANS_N0(int, wxFprintf, 2, (FILE*, const wxFormatString&), + wxCRT_FprintfNative, wxCRT_FprintfA) +inline int wxFprintf(FILE *f, const wxFormatString& s) +{ + return wxFprintf(f, "%s", s.InputAsString()); +} // va_list versions of printf functions simply forward to the respective // CRT function; note that they assume that va_list was created using @@ -426,10 +436,6 @@ wxVsnprintf(wchar_t *str, size_t size, const wxString& format, va_list argptr); } #define WX_DEFINE_SCANFUNC(name, numfixed, fixed, impl, passfixed) \ - inline int name(_WX_SCANFUNC_EXTRACT_ARGS(numfixed, fixed)) \ - { \ - return impl(_WX_SCANFUNC_EXTRACT_ARGS(numfixed, passfixed)); \ - } \ _WX_VARARG_ITER(_WX_VARARG_MAX_ARGS, \ _WX_DEFINE_SCANFUNC, \ dummy1, name, impl, passfixed, numfixed, fixed) diff --git a/src/common/strvararg.cpp b/src/common/strvararg.cpp index b06f3e6cf2..a10cdc26dd 100644 --- a/src/common/strvararg.cpp +++ b/src/common/strvararg.cpp @@ -611,6 +611,21 @@ const wchar_t* wxFormatString::AsWChar() } #endif // wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY +wxString wxFormatString::InputAsString() const +{ + if ( m_str ) + return *m_str; + if ( m_cstr ) + return m_cstr->AsString(); + if ( m_wchar ) + return wxString(m_wchar); + if ( m_char ) + return wxString(m_char); + + wxFAIL_MSG( "invalid wxFormatString - not initialized?" ); + return wxString(); +} + // ---------------------------------------------------------------------------- // wxFormatString::GetArgumentType() // ---------------------------------------------------------------------------- -- 2.45.2