aboutsummaryrefslogtreecommitdiff
path: root/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp')
-rw-r--r--core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp b/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
index 0d09b31fa..508810a3a 100644
--- a/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
+++ b/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,7 +8,7 @@
#include <vector>
-#include "core/fxcrt/fx_memory.h"
+#include "core/fxcrt/fx_safe_types.h"
namespace {
@@ -16,10 +16,12 @@ int ShiftOr(int val, int bitwise_or_val) {
return (val << 1) | bitwise_or_val;
}
-const struct ArithIntDecodeData {
+struct ArithIntDecodeData {
int nNeedBits;
int nValue;
-} g_ArithIntDecodeData[] = {
+};
+
+constexpr ArithIntDecodeData kArithIntDecodeData[] = {
{2, 0}, {4, 4}, {6, 20}, {8, 84}, {12, 340}, {32, 4436},
};
@@ -27,7 +29,7 @@ size_t RecursiveDecode(CJBig2_ArithDecoder* decoder,
std::vector<JBig2ArithCtx>* context,
int* prev,
size_t depth) {
- static const size_t kDepthEnd = FX_ArraySize(g_ArithIntDecodeData) - 1;
+ static const size_t kDepthEnd = std::size(kArithIntDecodeData) - 1;
if (depth == kDepthEnd)
return kDepthEnd;
@@ -45,7 +47,7 @@ CJBig2_ArithIntDecoder::CJBig2_ArithIntDecoder() {
m_IAx.resize(512);
}
-CJBig2_ArithIntDecoder::~CJBig2_ArithIntDecoder() {}
+CJBig2_ArithIntDecoder::~CJBig2_ArithIntDecoder() = default;
bool CJBig2_ArithIntDecoder::Decode(CJBig2_ArithDecoder* pArithDecoder,
int* nResult) {
@@ -60,15 +62,14 @@ bool CJBig2_ArithIntDecoder::Decode(CJBig2_ArithDecoder* pArithDecoder,
RecursiveDecode(pArithDecoder, &m_IAx, &PREV, 0);
int nTemp = 0;
- for (int i = 0; i < g_ArithIntDecodeData[nDecodeDataIndex].nNeedBits; ++i) {
+ for (int i = 0; i < kArithIntDecodeData[nDecodeDataIndex].nNeedBits; ++i) {
int D = pArithDecoder->Decode(&m_IAx[PREV]);
PREV = ShiftOr(PREV, D);
if (PREV >= 256)
PREV = (PREV & 511) | 256;
nTemp = ShiftOr(nTemp, D);
}
- pdfium::base::CheckedNumeric<int> safeValue =
- g_ArithIntDecodeData[nDecodeDataIndex].nValue;
+ FX_SAFE_INT32 safeValue = kArithIntDecodeData[nDecodeDataIndex].nValue;
safeValue += nTemp;
// Value does not fit in int.
@@ -90,7 +91,7 @@ CJBig2_ArithIaidDecoder::CJBig2_ArithIaidDecoder(unsigned char SBSYMCODELENA)
m_IAID.resize(static_cast<size_t>(1) << SBSYMCODELEN);
}
-CJBig2_ArithIaidDecoder::~CJBig2_ArithIaidDecoder() {}
+CJBig2_ArithIaidDecoder::~CJBig2_ArithIaidDecoder() = default;
void CJBig2_ArithIaidDecoder::Decode(CJBig2_ArithDecoder* pArithDecoder,
uint32_t* nResult) {