summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-16 21:09:57 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-16 21:09:57 +0000
commit0d32b8fda53e02c1036d39f7290d4f59f2b58ca4 (patch)
tree820ea3b95c5ef566ea6c6c11fd6f113f0f895e70 /fxjs
parent574ee81e426a7390e5cdf28f2fe8ec03f6c2da98 (diff)
downloadpdfium-0d32b8fda53e02c1036d39f7290d4f59f2b58ca4.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>
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cfxjse_resolveprocessor.cpp107
-rw-r--r--fxjs/xfa/cjx_hostpseudomodel.cpp20
2 files changed, 61 insertions, 66 deletions
diff --git a/fxjs/cfxjse_resolveprocessor.cpp b/fxjs/cfxjse_resolveprocessor.cpp
index 46163b55fc..2ca0838a7f 100644
--- a/fxjs/cfxjse_resolveprocessor.cpp
+++ b/fxjs/cfxjse_resolveprocessor.cpp
@@ -499,69 +499,66 @@ int32_t CFXJSE_ResolveProcessor::GetFilter(const WideStringView& wsExpression,
WideString& wsName = rnd.m_wsName;
WideString& wsCondition = rnd.m_wsCondition;
+ wchar_t* pNameBuf = wsName.GetBuffer(iLength - nStart);
+ wchar_t* pConditionBuf = wsCondition.GetBuffer(iLength - nStart);
int32_t nNameCount = 0;
int32_t nConditionCount = 0;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<wchar_t> pNameBuf = wsName.GetBuffer(iLength - nStart);
- pdfium::span<wchar_t> pConditionBuf =
- wsCondition.GetBuffer(iLength - nStart);
- std::vector<int32_t> stack;
- int32_t nType = -1;
- const wchar_t* pSrc = wsExpression.unterminated_c_str();
- wchar_t wPrev = 0;
- wchar_t wCur;
- bool bIsCondition = false;
- while (nStart < iLength) {
- wCur = pSrc[nStart++];
- if (wCur == '.') {
- if (wPrev == '\\') {
- pNameBuf[nNameCount - 1] = wPrev = '.';
- continue;
- }
- if (nNameCount == 0) {
- rnd.m_dwStyles |= XFA_RESOLVENODE_AnyChild;
- continue;
- }
-
- wchar_t wLookahead = nStart < iLength ? pSrc[nStart] : 0;
- if (wLookahead != '[' && wLookahead != '(' && nType < 0)
- break;
- }
- if (wCur == '[' || wCur == '(') {
- bIsCondition = true;
- } else if (wCur == '.' && nStart < iLength &&
- (pSrc[nStart] == '[' || pSrc[nStart] == '(')) {
- bIsCondition = true;
+ std::vector<int32_t> stack;
+ int32_t nType = -1;
+ const wchar_t* pSrc = wsExpression.unterminated_c_str();
+ wchar_t wPrev = 0;
+ wchar_t wCur;
+ bool bIsCondition = false;
+ while (nStart < iLength) {
+ wCur = pSrc[nStart++];
+ if (wCur == '.') {
+ if (wPrev == '\\') {
+ pNameBuf[nNameCount - 1] = wPrev = '.';
+ continue;
}
- if (bIsCondition)
- pConditionBuf[nConditionCount++] = wCur;
- else
- pNameBuf[nNameCount++] = wCur;
-
- if ((nType == 0 && wCur == ']') || (nType == 1 && wCur == ')') ||
- (nType == 2 && wCur == '"')) {
- nType = stack.empty() ? -1 : stack.back();
- if (!stack.empty())
- stack.pop_back();
- } else if (wCur == '[') {
- stack.push_back(nType);
- nType = 0;
- } else if (wCur == '(') {
- stack.push_back(nType);
- nType = 1;
- } else if (wCur == '"') {
- stack.push_back(nType);
- nType = 2;
+ if (nNameCount == 0) {
+ rnd.m_dwStyles |= XFA_RESOLVENODE_AnyChild;
+ continue;
}
- wPrev = wCur;
+
+ wchar_t wLookahead = nStart < iLength ? pSrc[nStart] : 0;
+ if (wLookahead != '[' && wLookahead != '(' && nType < 0)
+ break;
+ }
+ if (wCur == '[' || wCur == '(') {
+ bIsCondition = true;
+ } else if (wCur == '.' && nStart < iLength &&
+ (pSrc[nStart] == '[' || pSrc[nStart] == '(')) {
+ bIsCondition = true;
+ }
+ if (bIsCondition)
+ pConditionBuf[nConditionCount++] = wCur;
+ else
+ pNameBuf[nNameCount++] = wCur;
+
+ if ((nType == 0 && wCur == ']') || (nType == 1 && wCur == ')') ||
+ (nType == 2 && wCur == '"')) {
+ nType = stack.empty() ? -1 : stack.back();
+ if (!stack.empty())
+ stack.pop_back();
+ } else if (wCur == '[') {
+ stack.push_back(nType);
+ nType = 0;
+ } else if (wCur == '(') {
+ stack.push_back(nType);
+ nType = 1;
+ } else if (wCur == '"') {
+ stack.push_back(nType);
+ nType = 2;
}
- if (!stack.empty())
- return -1;
+ wPrev = wCur;
}
+ if (!stack.empty())
+ return -1;
+
wsName.ReleaseBuffer(nNameCount);
- wsCondition.ReleaseBuffer(nConditionCount);
wsName.Trim();
+ wsCondition.ReleaseBuffer(nConditionCount);
wsCondition.Trim();
rnd.m_uHashName =
static_cast<XFA_HashCode>(FX_HashCode_GetW(wsName.AsStringView(), false));
diff --git a/fxjs/xfa/cjx_hostpseudomodel.cpp b/fxjs/xfa/cjx_hostpseudomodel.cpp
index fe26d3161d..6ca431e78d 100644
--- a/fxjs/xfa/cjx_hostpseudomodel.cpp
+++ b/fxjs/xfa/cjx_hostpseudomodel.cpp
@@ -29,18 +29,16 @@ int32_t FilterName(const WideStringView& wsExpression,
if (nStart >= iLength)
return iLength;
+ wchar_t* pBuf = wsFilter.GetBuffer(iLength - nStart);
int32_t nCount = 0;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<wchar_t> 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;
- }
+ const wchar_t* pSrc = wsExpression.unterminated_c_str();
+ wchar_t wCur;
+ while (nStart < iLength) {
+ wCur = pSrc[nStart++];
+ if (wCur == ',')
+ break;
+
+ pBuf[nCount++] = wCur;
}
wsFilter.ReleaseBuffer(nCount);
wsFilter.Trim();