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 <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/cfx_bytestring.cpp b/core/fxcrt/cfx_bytestring.cpp
index 20497ec..073591a 100644
--- a/core/fxcrt/cfx_bytestring.cpp
+++ b/core/fxcrt/cfx_bytestring.cpp
@@ -473,20 +473,22 @@
}
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 24b7fb5..aadd1a2 100644
--- a/core/fxcrt/cfx_widestring.cpp
+++ b/core/fxcrt/cfx_widestring.cpp
@@ -665,17 +665,19 @@
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<int>(guess.value());
}
while (maxLen < 32 * 1024) {
- FX_VA_COPY(argListCopy, argList);
+ va_copy(argListCopy, argList);
bool bSufficientBuffer =
TryVSWPrintf(static_cast<FX_STRSIZE>(maxLen), format, argListCopy);
va_end(argListCopy);
diff --git a/core/fxcrt/fx_system.h b/core/fxcrt/fx_system.h
index 600d71c..7a95bf4 100644
--- a/core/fxcrt/fx_system.h
+++ b/core/fxcrt/fx_system.h
@@ -263,13 +263,4 @@
#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_