From 154e18f9a862975abecebe77b8f5fb418418d14c Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 12 Apr 2018 18:33:55 +0000 Subject: 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 --- fxjs/xfa/cjx_hostpseudomodel.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'fxjs/xfa') diff --git a/fxjs/xfa/cjx_hostpseudomodel.cpp b/fxjs/xfa/cjx_hostpseudomodel.cpp index 6ca431e78d..fe26d3161d 100644 --- a/fxjs/xfa/cjx_hostpseudomodel.cpp +++ b/fxjs/xfa/cjx_hostpseudomodel.cpp @@ -29,16 +29,18 @@ int32_t FilterName(const WideStringView& wsExpression, if (nStart >= iLength) return iLength; - wchar_t* pBuf = wsFilter.GetBuffer(iLength - nStart); int32_t nCount = 0; - const wchar_t* pSrc = wsExpression.unterminated_c_str(); - wchar_t wCur; - while (nStart < iLength) { - wCur = pSrc[nStart++]; - if (wCur == ',') - break; - - pBuf[nCount++] = wCur; + { + // Span's lifetime must end before ReleaseBuffer() below. + pdfium::span pBuf = wsFilter.GetBuffer(iLength - nStart); + const wchar_t* pSrc = wsExpression.unterminated_c_str(); + while (nStart < iLength) { + wchar_t wCur = pSrc[nStart++]; + if (wCur == ',') + break; + + pBuf[nCount++] = wCur; + } } wsFilter.ReleaseBuffer(nCount); wsFilter.Trim(); -- cgit v1.2.3