From 0d32b8fda53e02c1036d39f7290d4f59f2b58ca4 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 16 Apr 2018 21:09:57 +0000 Subject: Revert "Return pdfium::span from WideString::GetBuffer()." This reverts commit 154e18f9a862975abecebe77b8f5fb418418d14c. Reason for revert: Generate CL to merge to beta branch Original change's description: > Return pdfium::span 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 > Commit-Queue: Tom Sepez 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 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- xfa/fxfa/cxfa_textlayout.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'xfa/fxfa/cxfa_textlayout.cpp') 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 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, -- cgit v1.2.3