summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-11-06 18:49:21 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-06 18:49:21 +0000
commit438b1e32fb6cc096c65969405fd14cba21071d85 (patch)
tree5d997f6f5c3ac7c3689dd9bcb03002814bd7bc22 /core/fpdfapi
parent52f011adbf4216e3507ccd5be6753762e0ff7b64 (diff)
downloadpdfium-438b1e32fb6cc096c65969405fd14cba21071d85.tar.xz
Remove C-style casts in CPDF_PSEngine.
Fix a few other nits. Change-Id: I12f79b3f83d1695957ba067291f2ee03a7d189ca Reviewed-on: https://pdfium-review.googlesource.com/17810 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/page/cpdf_psengine.cpp84
-rw-r--r--core/fpdfapi/page/cpdf_psengine.h8
2 files changed, 48 insertions, 44 deletions
diff --git a/core/fpdfapi/page/cpdf_psengine.cpp b/core/fpdfapi/page/cpdf_psengine.cpp
index 63560fccc0..d879ead9c1 100644
--- a/core/fpdfapi/page/cpdf_psengine.cpp
+++ b/core/fpdfapi/page/cpdf_psengine.cpp
@@ -102,14 +102,14 @@ bool CPDF_PSProc::Execute(CPDF_PSEngine* pEngine) {
if (i == 0 || m_Operators[i - 1]->GetOp() != PSOP_PROC)
return false;
- if (static_cast<int>(pEngine->Pop()))
+ if (pEngine->PopInt())
m_Operators[i - 1]->GetProc()->Execute(pEngine);
} else if (op == PSOP_IFELSE) {
if (i < 2 || m_Operators[i - 1]->GetOp() != PSOP_PROC ||
m_Operators[i - 2]->GetOp() != PSOP_PROC) {
return false;
}
- size_t offset = static_cast<int>(pEngine->Pop()) ? 2 : 1;
+ size_t offset = pEngine->PopInt() ? 2 : 1;
m_Operators[i - offset]->GetProc()->Execute(pEngine);
} else {
pEngine->DoOperator(op);
@@ -123,7 +123,7 @@ CPDF_PSEngine::CPDF_PSEngine() : m_StackCount(0) {}
CPDF_PSEngine::~CPDF_PSEngine() {}
void CPDF_PSEngine::Push(float v) {
- if (m_StackCount < PSENGINE_STACKSIZE)
+ if (m_StackCount < kPSEngineStackSize)
m_Stack[m_StackCount++] = v;
}
@@ -131,6 +131,10 @@ float CPDF_PSEngine::Pop() {
return m_StackCount > 0 ? m_Stack[--m_StackCount] : 0;
}
+int CPDF_PSEngine::PopInt() {
+ return static_cast<int>(Pop());
+}
+
bool CPDF_PSEngine::Parse(const char* str, int size) {
CPDF_SimpleParser parser(reinterpret_cast<const uint8_t*>(str), size);
ByteStringView word = parser.GetWord();
@@ -197,8 +201,8 @@ bool CPDF_PSEngine::DoOperator(PDF_PSOP op) {
Push(d1 / d2);
break;
case PSOP_IDIV:
- i2 = static_cast<int>(Pop());
- i1 = static_cast<int>(Pop());
+ i2 = PopInt();
+ i1 = PopInt();
if (i2) {
result = i1;
result /= i2;
@@ -208,8 +212,8 @@ bool CPDF_PSEngine::DoOperator(PDF_PSOP op) {
}
break;
case PSOP_MOD:
- i2 = static_cast<int>(Pop());
- i1 = static_cast<int>(Pop());
+ i2 = PopInt();
+ i1 = PopInt();
if (i2) {
result = i1;
result %= i2;
@@ -224,40 +228,40 @@ bool CPDF_PSEngine::DoOperator(PDF_PSOP op) {
break;
case PSOP_ABS:
d1 = Pop();
- Push((float)fabs(d1));
+ Push(fabs(d1));
break;
case PSOP_CEILING:
d1 = Pop();
- Push((float)ceil(d1));
+ Push(ceil(d1));
break;
case PSOP_FLOOR:
d1 = Pop();
- Push((float)floor(d1));
+ Push(floor(d1));
break;
case PSOP_ROUND:
d1 = Pop();
Push(FXSYS_round(d1));
break;
case PSOP_TRUNCATE:
- i1 = (int)Pop();
+ i1 = PopInt();
Push(i1);
break;
case PSOP_SQRT:
d1 = Pop();
- Push((float)sqrt(d1));
+ Push(sqrt(d1));
break;
case PSOP_SIN:
d1 = Pop();
- Push((float)sin(d1 * FX_PI / 180.0f));
+ Push(sin(d1 * FX_PI / 180.0f));
break;
case PSOP_COS:
d1 = Pop();
- Push((float)cos(d1 * FX_PI / 180.0f));
+ Push(cos(d1 * FX_PI / 180.0f));
break;
case PSOP_ATAN:
d2 = Pop();
d1 = Pop();
- d1 = (float)(atan2(d1, d2) * 180.0 / FX_PI);
+ d1 = atan2(d1, d2) * 180.0 / FX_PI;
if (d1 < 0) {
d1 += 360;
}
@@ -266,18 +270,18 @@ bool CPDF_PSEngine::DoOperator(PDF_PSOP op) {
case PSOP_EXP:
d2 = Pop();
d1 = Pop();
- Push((float)FXSYS_pow(d1, d2));
+ Push(FXSYS_pow(d1, d2));
break;
case PSOP_LN:
d1 = Pop();
- Push((float)log(d1));
+ Push(log(d1));
break;
case PSOP_LOG:
d1 = Pop();
- Push((float)log10(d1));
+ Push(log10(d1));
break;
case PSOP_CVI:
- i1 = (int)Pop();
+ i1 = PopInt();
Push(i1);
break;
case PSOP_CVR:
@@ -285,55 +289,55 @@ bool CPDF_PSEngine::DoOperator(PDF_PSOP op) {
case PSOP_EQ:
d2 = Pop();
d1 = Pop();
- Push((int)(d1 == d2));
+ Push(d1 == d2);
break;
case PSOP_NE:
d2 = Pop();
d1 = Pop();
- Push((int)(d1 != d2));
+ Push(d1 != d2);
break;
case PSOP_GT:
d2 = Pop();
d1 = Pop();
- Push((int)(d1 > d2));
+ Push(d1 > d2);
break;
case PSOP_GE:
d2 = Pop();
d1 = Pop();
- Push((int)(d1 >= d2));
+ Push(d1 >= d2);
break;
case PSOP_LT:
d2 = Pop();
d1 = Pop();
- Push((int)(d1 < d2));
+ Push(d1 < d2);
break;
case PSOP_LE:
d2 = Pop();
d1 = Pop();
- Push((int)(d1 <= d2));
+ Push(d1 <= d2);
break;
case PSOP_AND:
- i1 = (int)Pop();
- i2 = (int)Pop();
+ i1 = PopInt();
+ i2 = PopInt();
Push(i1 & i2);
break;
case PSOP_OR:
- i1 = (int)Pop();
- i2 = (int)Pop();
+ i1 = PopInt();
+ i2 = PopInt();
Push(i1 | i2);
break;
case PSOP_XOR:
- i1 = (int)Pop();
- i2 = (int)Pop();
+ i1 = PopInt();
+ i2 = PopInt();
Push(i1 ^ i2);
break;
case PSOP_NOT:
- i1 = (int)Pop();
- Push((int)!i1);
+ i1 = PopInt();
+ Push(!i1);
break;
case PSOP_BITSHIFT: {
- int shift = (int)Pop();
- result = (int)Pop();
+ int shift = PopInt();
+ result = PopInt();
if (shift > 0) {
result <<= shift;
} else {
@@ -365,8 +369,8 @@ bool CPDF_PSEngine::DoOperator(PDF_PSOP op) {
Push(d1);
break;
case PSOP_COPY: {
- int n = static_cast<int>(Pop());
- if (n < 0 || m_StackCount + n > PSENGINE_STACKSIZE ||
+ int n = PopInt();
+ if (n < 0 || m_StackCount + n > kPSEngineStackSize ||
n > static_cast<int>(m_StackCount))
break;
for (int i = 0; i < n; i++)
@@ -375,15 +379,15 @@ bool CPDF_PSEngine::DoOperator(PDF_PSOP op) {
break;
}
case PSOP_INDEX: {
- int n = static_cast<int>(Pop());
+ int n = PopInt();
if (n < 0 || n >= static_cast<int>(m_StackCount))
break;
Push(m_Stack[m_StackCount - n - 1]);
break;
}
case PSOP_ROLL: {
- int j = static_cast<int>(Pop());
- int n = static_cast<int>(Pop());
+ int j = PopInt();
+ int n = PopInt();
if (j == 0 || n == 0 || m_StackCount == 0)
break;
if (n < 0 || n > static_cast<int>(m_StackCount))
diff --git a/core/fpdfapi/page/cpdf_psengine.h b/core/fpdfapi/page/cpdf_psengine.h
index 607d81065d..0d5eadd78e 100644
--- a/core/fpdfapi/page/cpdf_psengine.h
+++ b/core/fpdfapi/page/cpdf_psengine.h
@@ -16,7 +16,7 @@ class CPDF_PSEngine;
class CPDF_PSOP;
class CPDF_SimpleParser;
-enum PDF_PSOP {
+enum PDF_PSOP : uint8_t {
PSOP_ADD,
PSOP_SUB,
PSOP_MUL,
@@ -63,8 +63,6 @@ enum PDF_PSOP {
PSOP_CONST
};
-constexpr uint32_t PSENGINE_STACKSIZE = 100;
-
class CPDF_PSProc {
public:
CPDF_PSProc();
@@ -89,10 +87,12 @@ class CPDF_PSEngine {
void Reset() { m_StackCount = 0; }
void Push(float value);
float Pop();
+ int PopInt();
uint32_t GetStackSize() const { return m_StackCount; }
private:
- float m_Stack[PSENGINE_STACKSIZE];
+ static constexpr uint32_t kPSEngineStackSize = 100;
+ float m_Stack[kPSEngineStackSize];
uint32_t m_StackCount;
CPDF_PSProc m_MainProc;
};