summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-10-12 09:37:28 -0700
committerCommit bot <commit-bot@chromium.org>2016-10-12 09:37:28 -0700
commit47cbc06ef6f528e4d30a869ec533d010ee79b064 (patch)
treeebe4ee69194e32de371999268749cef7ef114305 /core/fpdfapi
parenta30537f8b07492489e81414c9037af90c8b1448e (diff)
downloadpdfium-47cbc06ef6f528e4d30a869ec533d010ee79b064.tar.xz
Optimize roll operator in CPDF_PSEngine.
Rolling 0 times is a no-op. Rolling 0 items is a no-op. Rolling N items J times is the same as rolling N items J % N times. This also avoids an integer overflow corner case. BUG=chromium:648077 Review-Url: https://codereview.chromium.org/2412833002
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/page/fpdf_page_func.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/core/fpdfapi/page/fpdf_page_func.cpp b/core/fpdfapi/page/fpdf_page_func.cpp
index bf44a1e7c5..6af787ea49 100644
--- a/core/fpdfapi/page/fpdf_page_func.cpp
+++ b/core/fpdfapi/page/fpdf_page_func.cpp
@@ -376,10 +376,12 @@ FX_BOOL CPDF_PSEngine::DoOperator(PDF_PSOP op) {
case PSOP_ROLL: {
int j = static_cast<int>(Pop());
int n = static_cast<int>(Pop());
- if (m_StackCount == 0)
+ if (j == 0 || n == 0 || m_StackCount == 0)
break;
if (n < 0 || n > static_cast<int>(m_StackCount))
break;
+
+ j %= n;
if (j < 0) {
for (int i = 0; i < -j; i++) {
FX_FLOAT first = m_Stack[m_StackCount - n];