added wxVaCopy() and use it to fix wxVsnprintf() crash (see bug 1017651)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29604 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2004-10-02 18:32:31 +00:00
parent ebb97a41da
commit d85cfb3784
3 changed files with 64 additions and 1 deletions

View File

@@ -237,6 +237,7 @@ the corresponding topic.
\helpref{wxUnix2DosFilename}{wxunix2dosfilename}\\
\helpref{wxUnsetEnv}{wxunsetenv}\\
\helpref{wxUsleep}{wxusleep}\\
\helpref{wxVaCopy}{wxvacopy}\\
\helpref{wxVsnprintf}{wxvsnprintf}\\
\helpref{wxWakeUpIdle}{wxwakeupidle}\\
\helpref{wxWriteResource}{wxwriteresource}\\
@@ -2977,6 +2978,19 @@ allows to define unsigned 64 bit compile time constants:
\helpref{wxLL}{wxll}, \helpref{wxLongLong}{wxlonglong}
\membersection{wxVaCopy}\label{wxvacopy}
\func{void}{wxVaCopy}{\param{va\_list }{argptrDst}, \param{va\_list}{argptrSrc}}
This macro is the same as the standard C99 \texttt{va\_copy} for the compilers
which support it or its replacement for those that don't. It must be used to
preserve the value of a \texttt{va\_list} object if you need to use it after
passing it to another function because it can be modified by the latter.
As with \texttt{va\_start}, each call to \texttt{wxVaCopy} must have a matching
\texttt{va\_end}.
\membersection{::wxWriteResource}\label{wxwriteresource}
\func{bool}{wxWriteResource}{\param{const wxString\& }{section}, \param{const wxString\& }{entry},

View File

@@ -323,6 +323,50 @@ typedef int wxWindowID;
#endif
#endif
/* provide replacement for C99 va_copy() if the compiler doesn't have it */
/* could be already defined by configure or the user */
#ifndef wxVaCopy
/* if va_copy is a macro or configure detected that we have it, use it */
#if defined(va_copy) || defined(HAVE_VA_COPY)
#define wxVaCopy va_copy
#else /* no va_copy, try to provide a replacement */
/*
configure tries to determine whether va_list is an array or struct
type, but it may not be used under Windows, so deal with a few
special cases.
*/
#ifdef __WATCOMC__
/* Watcom uses array type for va_list except for PPC and Alpha */
#if !defined(__PPC__) && !defined(__AXP__)
#define VA_LIST_IS_ARRAY
#endif
#endif /* __WATCOMC__ */
#if defined(__PPC__) && (defined(_CALL_SYSV) || defined (_WIN32))
/*
PPC using SysV ABI and NT/PPC are special in that they use an
extra level of indirection.
*/
#define VA_LIST_IS_POINTER
#endif /* SysV or Win32 on __PPC__ */
/*
note that we use memmove(), not memcpy(), in case anybody tries
to do wxVaCopy(ap, ap)
*/
#if defined(VA_LIST_IS_POINTER)
#define wxVaCopy(d, s) memmove(*(d), *(s), sizeof(va_list))
#elif defined(VA_LIST_IS_ARRAY)
#define wxVaCopy(d, s) memmove((d), (s), sizeof(va_list))
#else /* we can only hope that va_lists are simple lvalues */
#define wxVaCopy(d, s) ((d) = (s))
#endif
#endif /* va_copy/!va_copy */
#endif // wxVaCopy
/* ---------------------------------------------------------------------------- */
/* portable calling conventions macros */
/* ---------------------------------------------------------------------------- */

View File

@@ -1727,7 +1727,12 @@ int wxString::PrintfV(const wxChar* pszFormat, va_list argptr)
return -1;
}
len = wxVsnprintf(buf, size, pszFormat, argptr);
// wxVsnprintf() may modify the original arg pointer, so pass it
// only a copy
va_list argptrcopy;
wxVaCopy(argptrcopy, argptr);
len = wxVsnprintf(buf, size, pszFormat, argptrcopy);
va_end(argptrcopy);
// some implementations of vsnprintf() don't NUL terminate
// the string if there is not enough space for it so