diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-04-18 20:14:40 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-18 20:14:40 +0000 |
commit | 4e636b74000b0c97be28ccc52fa1f2a5bb8c80ca (patch) | |
tree | a7d1e266ab10cde42f07dd727f1c0f8dd1a9045a /xfa/fxfa | |
parent | 24582d2c000f11ed4bfcb2579b79d10afc809062 (diff) | |
download | pdfium-4e636b74000b0c97be28ccc52fa1f2a5bb8c80ca.tar.xz |
Revert "Return pdfium::span<wchar_t> from WideString::GetBuffer()."
This reverts commit 154e18f9a862975abecebe77b8f5fb418418d14c.
Reason for revert: Generate CL to merge to beta branch
Original change's description:
> Return pdfium::span<wchar_t> from WideString::GetBuffer().
>
> Adds bounds checking "for free", but beware of span outliving
> a ReleaseBuffer() call. Scoping as such avoids the possibility
> of using an invalid span (and it is flagged as a lifetime issue).
>
> Change-Id: Ica63f4b1429823d0254ec6951aeaeb08160cb93c
> Reviewed-on: https://pdfium-review.googlesource.com/30310
> Reviewed-by: dsinclair <dsinclair@chromium.org>
> Commit-Queue: Tom Sepez <tsepez@chromium.org>
TBR=tsepez@chromium.org,dsinclair@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: Ie1ec9434215584a024538ca8edeb59dea555af48
Reviewed-on: https://pdfium-review.googlesource.com/30830
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
(cherry picked from commit 0d32b8fda53e02c1036d39f7290d4f59f2b58ca4)
Reviewed-on: https://pdfium-review.googlesource.com/30951
Diffstat (limited to 'xfa/fxfa')
-rw-r--r-- | xfa/fxfa/cxfa_textlayout.cpp | 28 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_localevalue.cpp | 44 |
2 files changed, 34 insertions, 38 deletions
diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp index 5359a340e5..e360c16dde 100644 --- a/xfa/fxfa/cxfa_textlayout.cpp +++ b/xfa/fxfa/cxfa_textlayout.cpp @@ -911,23 +911,21 @@ void CXFA_TextLayout::ProcessText(WideString& wsText) { if (iLen == 0) return; + wchar_t* psz = wsText.GetBuffer(iLen); int32_t iTrimLeft = 0; - { - // Span's lifetime must end before ReleaseBuffer() below. - pdfium::span<wchar_t> psz = wsText.GetBuffer(iLen); - wchar_t wPrev = 0; - for (int32_t i = 0; i < iLen; i++) { - wchar_t wch = psz[i]; - if (wch < 0x20) - wch = 0x20; - if (wch == 0x20 && wPrev == 0x20) - continue; - - wPrev = wch; - psz[iTrimLeft++] = wch; - } + wchar_t wch = 0, wPrev = 0; + for (int32_t i = 0; i < iLen; i++) { + wch = psz[i]; + if (wch < 0x20) + wch = 0x20; + if (wch == 0x20 && wPrev == 0x20) + continue; + + wPrev = wch; + psz[iTrimLeft++] = wch; } - wsText.ReleaseBuffer(iTrimLeft); + wsText.ReleaseBuffer(iLen); + wsText = wsText.Left(iTrimLeft); } void CXFA_TextLayout::EndBreak(CFX_BreakType dwStatus, diff --git a/xfa/fxfa/parser/cxfa_localevalue.cpp b/xfa/fxfa/parser/cxfa_localevalue.cpp index b129960f7d..8ef67e5183 100644 --- a/xfa/fxfa/parser/cxfa_localevalue.cpp +++ b/xfa/fxfa/parser/cxfa_localevalue.cpp @@ -682,34 +682,32 @@ void CXFA_LocaleValue::GetNumericFormat(WideString& wsFormat, int32_t nDecLen) { ASSERT(wsFormat.IsEmpty()); ASSERT(nIntLen >= -1 && nDecLen >= -1); + int32_t nTotalLen = (nIntLen >= 0 ? nIntLen : 2) + 1 + (nDecLen >= 0 ? nDecLen : 2) + (nDecLen == 0 ? 0 : 1); - { - // Span's lifetime must end before ReleaseBuffer() below. - pdfium::span<wchar_t> lpBuf = wsFormat.GetBuffer(nTotalLen); - int32_t nPos = 0; - lpBuf[nPos++] = L's'; - - if (nIntLen == -1) { + wchar_t* lpBuf = wsFormat.GetBuffer(nTotalLen); + int32_t nPos = 0; + lpBuf[nPos++] = L's'; + + if (nIntLen == -1) { + lpBuf[nPos++] = L'z'; + lpBuf[nPos++] = L'*'; + } else { + while (nIntLen) { lpBuf[nPos++] = L'z'; - lpBuf[nPos++] = L'*'; - } else { - while (nIntLen) { - lpBuf[nPos++] = L'z'; - nIntLen--; - } - } - if (nDecLen != 0) { - lpBuf[nPos++] = L'.'; + nIntLen--; } - if (nDecLen == -1) { + } + if (nDecLen != 0) { + lpBuf[nPos++] = L'.'; + } + if (nDecLen == -1) { + lpBuf[nPos++] = L'z'; + lpBuf[nPos++] = L'*'; + } else { + while (nDecLen) { lpBuf[nPos++] = L'z'; - lpBuf[nPos++] = L'*'; - } else { - while (nDecLen) { - lpBuf[nPos++] = L'z'; - nDecLen--; - } + nDecLen--; } } wsFormat.ReleaseBuffer(nTotalLen); |