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
This commit is contained in:
@@ -154,11 +154,15 @@ public:
|
|||||||
// n-th variadic argument desired representation
|
// n-th variadic argument desired representation
|
||||||
ArgumentType GetArgumentType(unsigned n) const;
|
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
|
#if !wxUSE_UNICODE_WCHAR
|
||||||
operator const char*() const
|
operator const char*() const
|
||||||
{ return const_cast<wxFormatString*>(this)->AsChar(); }
|
{ return const_cast<wxFormatString*>(this)->AsChar(); }
|
||||||
private:
|
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()
|
// to char, while AsChar() takes the the string returned by InputAsChar()
|
||||||
// and does format string conversion on it as well (and similarly for
|
// and does format string conversion on it as well (and similarly for
|
||||||
// ..AsWChar() below)
|
// ..AsWChar() below)
|
||||||
|
@@ -281,10 +281,20 @@
|
|||||||
#define wxCRT_FprintfNative wxCRT_FprintfA
|
#define wxCRT_FprintfNative wxCRT_FprintfA
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
WX_DEFINE_VARARG_FUNC(int, wxPrintf, 1, (const wxFormatString&),
|
|
||||||
|
WX_DEFINE_VARARG_FUNC_SANS_N0(int, wxPrintf, 1, (const wxFormatString&),
|
||||||
wxCRT_PrintfNative, wxCRT_PrintfA)
|
wxCRT_PrintfNative, wxCRT_PrintfA)
|
||||||
WX_DEFINE_VARARG_FUNC(int, wxFprintf, 2, (FILE*, const wxFormatString&),
|
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)
|
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
|
// va_list versions of printf functions simply forward to the respective
|
||||||
// CRT function; note that they assume that va_list was created using
|
// 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) \
|
#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_VARARG_ITER(_WX_VARARG_MAX_ARGS, \
|
||||||
_WX_DEFINE_SCANFUNC, \
|
_WX_DEFINE_SCANFUNC, \
|
||||||
dummy1, name, impl, passfixed, numfixed, fixed)
|
dummy1, name, impl, passfixed, numfixed, fixed)
|
||||||
|
@@ -611,6 +611,21 @@ const wchar_t* wxFormatString::AsWChar()
|
|||||||
}
|
}
|
||||||
#endif // wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY
|
#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()
|
// wxFormatString::GetArgumentType()
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user