Do not shrink buffer before examining last byte in TryVSWPrintF

Bug: 707479
Change-Id: I6deea8ca2408df8715e639c8ff161cbb3d5f8296
Reviewed-on: https://pdfium-review.googlesource.com/3595
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/cfx_widestring.cpp b/core/fxcrt/cfx_widestring.cpp
index 49a62da..c3be23a 100644
--- a/core/fxcrt/cfx_widestring.cpp
+++ b/core/fxcrt/cfx_widestring.cpp
@@ -611,8 +611,9 @@
   // See https://crbug.com/705912.
   memset(m_pData->m_String, 0, (size + 1) * sizeof(wchar_t));
   int ret = vswprintf(m_pData->m_String, size + 1, pFormat, argList);
+  bool bSufficientBuffer = ret >= 0 || m_pData->m_String[size - 1] == 0;
   ReleaseBuffer();
-  return ret >= 0 || m_pData->m_String[size - 1] == 0;
+  return bSufficientBuffer;
 }
 
 void CFX_WideString::FormatV(const wchar_t* pFormat, va_list argList) {
@@ -627,9 +628,9 @@
   }
   while (nMaxLen < 32 * 1024) {
     FX_VA_COPY(argListCopy, argList);
-    bool bRetryPointless = TryVSWPrintf(nMaxLen, pFormat, argListCopy);
+    bool bSufficientBuffer = TryVSWPrintf(nMaxLen, pFormat, argListCopy);
     va_end(argListCopy);
-    if (bRetryPointless)
+    if (bSufficientBuffer)
       break;
     nMaxLen *= 2;
   }