From f2ca50ffa2d26a6c023add24e92adbe6b28bfcc9 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 12 Sep 2017 14:49:29 -0700 Subject: Avoid double va_list traversal in CFX_WideString::FormatV Speculative fix for bug. Also remove FX_VA_COPY as va_copy should be fine on all ports nowdays (we think). Bug: 763965 Change-Id: I5c321d5624d00b3b2f262ec599e4382f02b744ff Reviewed-on: https://pdfium-review.googlesource.com/13790 Commit-Queue: Lei Zhang Reviewed-by: Lei Zhang --- core/fxcrt/cfx_bytestring.cpp | 12 +++++++----- core/fxcrt/cfx_widestring.cpp | 6 ++++-- core/fxcrt/fx_system.h | 9 --------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/core/fxcrt/cfx_bytestring.cpp b/core/fxcrt/cfx_bytestring.cpp index 20497ecc32..073591a5ab 100644 --- a/core/fxcrt/cfx_bytestring.cpp +++ b/core/fxcrt/cfx_bytestring.cpp @@ -473,20 +473,22 @@ CFX_ByteString CFX_ByteString::FormatInteger(int i) { } void CFX_ByteString::FormatV(const char* pFormat, va_list argList) { - va_list argListSave; - FX_VA_COPY(argListSave, argList); - FX_STRSIZE nMaxLen = vsnprintf(nullptr, 0, pFormat, argList); + va_list argListCopy; + va_copy(argListCopy, argList); + FX_STRSIZE nMaxLen = vsnprintf(nullptr, 0, pFormat, argListCopy); + va_end(argListCopy); if (nMaxLen > 0) { GetBuffer(nMaxLen); if (m_pData) { // In the following two calls, there's always space in the buffer for // a terminating NUL that's not included in nMaxLen. memset(m_pData->m_String, 0, nMaxLen + 1); - vsnprintf(m_pData->m_String, nMaxLen + 1, pFormat, argListSave); + va_copy(argListCopy, argList); + vsnprintf(m_pData->m_String, nMaxLen + 1, pFormat, argListCopy); + va_end(argListCopy); ReleaseBuffer(GetStringLength()); } } - va_end(argListSave); } void CFX_ByteString::Format(const char* pFormat, ...) { diff --git a/core/fxcrt/cfx_widestring.cpp b/core/fxcrt/cfx_widestring.cpp index 24b7fb59d3..aadd1a29ed 100644 --- a/core/fxcrt/cfx_widestring.cpp +++ b/core/fxcrt/cfx_widestring.cpp @@ -665,17 +665,19 @@ bool CFX_WideString::TryVSWPrintf(FX_STRSIZE size, void CFX_WideString::FormatV(const wchar_t* format, va_list argList) { va_list argListCopy; - FX_VA_COPY(argListCopy, argList); + va_copy(argListCopy, argList); int maxLen = vswprintf(nullptr, 0, format, argListCopy); va_end(argListCopy); if (maxLen <= 0) { + va_copy(argListCopy, argList); auto guess = GuessSizeForVSWPrintf(format, argListCopy); + va_end(argListCopy); if (!guess.has_value()) return; maxLen = pdfium::base::checked_cast(guess.value()); } while (maxLen < 32 * 1024) { - FX_VA_COPY(argListCopy, argList); + va_copy(argListCopy, argList); bool bSufficientBuffer = TryVSWPrintf(static_cast(maxLen), format, argListCopy); va_end(argListCopy); diff --git a/core/fxcrt/fx_system.h b/core/fxcrt/fx_system.h index 600d71c72b..7a95bf4fd0 100644 --- a/core/fxcrt/fx_system.h +++ b/core/fxcrt/fx_system.h @@ -263,13 +263,4 @@ int FXSYS_round(float f); #define NEVER_INLINE __attribute__((__noinline__)) #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -// Handle differnces between platform's variadic function implementations. -#if defined(__ARMCC_VERSION) || \ - (!defined(_MSC_VER) && (_FX_CPU_ == _FX_X64_ || _FX_CPU_ == _FX_IA64_ || \ - _FX_CPU_ == _FX_ARM64_)) -#define FX_VA_COPY(dst, src) va_copy((dst), (src)) -#else -#define FX_VA_COPY(dst, src) ((dst) = (src)) -#endif - #endif // CORE_FXCRT_FX_SYSTEM_H_ -- cgit v1.2.3