diff options
author | Lei Zhang <thestig@chromium.org> | 2015-10-16 16:22:37 -0700 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2015-10-16 16:22:37 -0700 |
commit | c40ccaff017691b7d31e0597863bfb954aebd739 (patch) | |
tree | 4f5f09c672393e130037826256ab182e2d2ae7f5 /core/src/fxcodec/jbig2 | |
parent | a725bc9a3525256976c112b2b5a429a119cf9b69 (diff) | |
download | pdfium-c40ccaff017691b7d31e0597863bfb954aebd739.tar.xz |
Merge to XFA: Fix a bunch of sign mismatch warnings.
Also remove some gotos and move code into an anonymous namespace.
And then do the partial revert to avoid size_t going negative.
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1356373003 .
Review URL: https://codereview.chromium.org/1400723002 .
(cherry picked from commit d03ba8d1a5928e8f3f6bd7da063b53b0bc40abfd)
(cherry picked from commit a398ca611d1925182ff6a4e8b2b43c277c364dc0)
Review URL: https://codereview.chromium.org/1406373002 .
Diffstat (limited to 'core/src/fxcodec/jbig2')
-rw-r--r-- | core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp | 47 | ||||
-rw-r--r-- | core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.h | 4 | ||||
-rw-r--r-- | core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp | 43 | ||||
-rw-r--r-- | core/src/fxcodec/jbig2/JBig2_HuffmanTable.h | 6 |
4 files changed, 48 insertions, 52 deletions
diff --git a/core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp b/core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp index 61a45bebae..cbbe6af70e 100644 --- a/core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp +++ b/core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp @@ -8,47 +8,44 @@ #include "JBig2_Define.h" -CJBig2_HuffmanDecoder::CJBig2_HuffmanDecoder(CJBig2_BitStream* pStream) { - m_pStream = pStream; +CJBig2_HuffmanDecoder::CJBig2_HuffmanDecoder(CJBig2_BitStream* pStream) + : m_pStream(pStream) { } + CJBig2_HuffmanDecoder::~CJBig2_HuffmanDecoder() {} + int CJBig2_HuffmanDecoder::decodeAValue(CJBig2_HuffmanTable* pTable, int* nResult) { - int i; int nVal = 0; int nBits = 0; - FX_DWORD nTmp; while (1) { - if (m_pStream->read1Bit(&nTmp) == -1) { + FX_DWORD nTmp; + if (m_pStream->read1Bit(&nTmp) == -1) return -1; - } + nVal = (nVal << 1) | nTmp; - nBits++; - for (i = 0; i < pTable->NTEMP; i++) { + ++nBits; + for (FX_DWORD i = 0; i < pTable->NTEMP; ++i) { if ((pTable->PREFLEN[i] == nBits) && (pTable->CODES[i] == nVal)) { - if ((pTable->HTOOB == 1) && (i == pTable->NTEMP - 1)) { + if ((pTable->HTOOB == 1) && (i == pTable->NTEMP - 1)) return JBIG2_OOB; - } - if (m_pStream->readNBits(pTable->RANGELEN[i], &nTmp) == -1) { + + if (m_pStream->readNBits(pTable->RANGELEN[i], &nTmp) == -1) return -1; - } + if (pTable->HTOOB) { - if (i == pTable->NTEMP - 3) { + if (i == pTable->NTEMP - 3) *nResult = pTable->RANGELOW[i] - nTmp; - return 0; - } else { + else *nResult = pTable->RANGELOW[i] + nTmp; - return 0; - } - } else { - if (i == pTable->NTEMP - 2) { - *nResult = pTable->RANGELOW[i] - nTmp; - return 0; - } else { - *nResult = pTable->RANGELOW[i] + nTmp; - return 0; - } + return 0; } + + if (i == pTable->NTEMP - 2) + *nResult = pTable->RANGELOW[i] - nTmp; + else + *nResult = pTable->RANGELOW[i] + nTmp; + return 0; } } } diff --git a/core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.h b/core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.h index c972aae074..e15e891060 100644 --- a/core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.h +++ b/core/src/fxcodec/jbig2/JBig2_HuffmanDecoder.h @@ -10,13 +10,13 @@ #include "JBig2_HuffmanTable.h" class CJBig2_HuffmanDecoder { public: - CJBig2_HuffmanDecoder(CJBig2_BitStream* pStream); + explicit CJBig2_HuffmanDecoder(CJBig2_BitStream* pStream); ~CJBig2_HuffmanDecoder(); int decodeAValue(CJBig2_HuffmanTable* pTable, int* nResult); private: - CJBig2_BitStream* m_pStream; + CJBig2_BitStream* const m_pStream; }; #endif diff --git a/core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp b/core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp index a09d152052..4effbfadef 100644 --- a/core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp +++ b/core/src/fxcodec/jbig2/JBig2_HuffmanTable.cpp @@ -35,25 +35,22 @@ CJBig2_HuffmanTable::~CJBig2_HuffmanTable() { void CJBig2_HuffmanTable::init() { HTOOB = FALSE; NTEMP = 0; - CODES = NULL; - PREFLEN = NULL; - RANGELEN = NULL; - RANGELOW = NULL; + CODES = nullptr; + PREFLEN = nullptr; + RANGELEN = nullptr; + RANGELOW = nullptr; } int CJBig2_HuffmanTable::parseFromStandardTable(const JBig2TableLine* pTable, int nLines, FX_BOOL bHTOOB) { - int CURLEN, LENMAX, CURCODE, CURTEMP; - int* LENCOUNT; - int* FIRSTCODE; HTOOB = bHTOOB; NTEMP = nLines; CODES = FX_Alloc(int, NTEMP); PREFLEN = FX_Alloc(int, NTEMP); RANGELEN = FX_Alloc(int, NTEMP); RANGELOW = FX_Alloc(int, NTEMP); - LENMAX = 0; - for (int i = 0; i < NTEMP; i++) { + int LENMAX = 0; + for (FX_DWORD i = 0; i < NTEMP; ++i) { PREFLEN[i] = pTable[i].PREFLEN; RANGELEN[i] = pTable[i].RANDELEN; RANGELOW[i] = pTable[i].RANGELOW; @@ -61,19 +58,19 @@ int CJBig2_HuffmanTable::parseFromStandardTable(const JBig2TableLine* pTable, LENMAX = PREFLEN[i]; } } - LENCOUNT = FX_Alloc(int, LENMAX + 1); + int* LENCOUNT = FX_Alloc(int, LENMAX + 1); JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1)); - FIRSTCODE = FX_Alloc(int, LENMAX + 1); - for (int i = 0; i < NTEMP; i++) { - LENCOUNT[PREFLEN[i]]++; - } - CURLEN = 1; + int* FIRSTCODE = FX_Alloc(int, LENMAX + 1); + for (FX_DWORD i = 0; i < NTEMP; ++i) + ++LENCOUNT[PREFLEN[i]]; + + int CURLEN = 1; FIRSTCODE[0] = 0; LENCOUNT[0] = 0; while (CURLEN <= LENMAX) { FIRSTCODE[CURLEN] = (FIRSTCODE[CURLEN - 1] + LENCOUNT[CURLEN - 1]) << 1; - CURCODE = FIRSTCODE[CURLEN]; - CURTEMP = 0; + int CURCODE = FIRSTCODE[CURLEN]; + FX_DWORD CURTEMP = 0; while (CURTEMP < NTEMP) { if (PREFLEN[CURTEMP] == CURLEN) { CODES[CURTEMP] = CURCODE; @@ -109,6 +106,7 @@ int CJBig2_HuffmanTable::parseFromCodedBuffer(CJBig2_BitStream* pStream) { pStream->readInteger(&HTHIGH) == -1 || HTLOW > HTHIGH) { return FALSE; } + FX_DWORD nSize = 16; PREFLEN = FX_Alloc(int, nSize); RANGELEN = FX_Alloc(int, nSize); @@ -131,7 +129,7 @@ int CJBig2_HuffmanTable::parseFromCodedBuffer(CJBig2_BitStream* pStream) { RANGELEN[NTEMP] = 32; RANGELOW[NTEMP] = HTLOW - 1; - NTEMP = NTEMP + 1; + ++NTEMP; HT_CHECK_MEMORY_ADJUST if (pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1) return FALSE; @@ -143,18 +141,19 @@ int CJBig2_HuffmanTable::parseFromCodedBuffer(CJBig2_BitStream* pStream) { HT_CHECK_MEMORY_ADJUST if (pStream->readNBits(HTPS, &PREFLEN[NTEMP]) == -1) return FALSE; - NTEMP = NTEMP + 1; + + ++NTEMP; } CODES = FX_Alloc(int, NTEMP); int LENMAX = 0; - for (int i = 0; i < NTEMP; i++) { + for (FX_DWORD i = 0; i < NTEMP; ++i) { if (PREFLEN[i] > LENMAX) { LENMAX = PREFLEN[i]; } } std::vector<int> LENCOUNT(LENMAX + 1); - for (int i = 0; i < NTEMP; ++i) + for (FX_DWORD i = 0; i < NTEMP; ++i) LENCOUNT[PREFLEN[i]]++; LENCOUNT[0] = 0; @@ -163,7 +162,7 @@ int CJBig2_HuffmanTable::parseFromCodedBuffer(CJBig2_BitStream* pStream) { for (int i = 0; i <= LENMAX; ++i) { FIRSTCODE[i] = (FIRSTCODE[i - 1] + LENCOUNT[i - 1]) << 1; int CURCODE = FIRSTCODE[i]; - for (int j = 0; j < NTEMP; ++j) { + for (FX_DWORD j = 0; j < NTEMP; ++j) { if (PREFLEN[j] == i) CODES[j] = CURCODE++; } diff --git a/core/src/fxcodec/jbig2/JBig2_HuffmanTable.h b/core/src/fxcodec/jbig2/JBig2_HuffmanTable.h index 7c843cf91b..fe8294dc7e 100644 --- a/core/src/fxcodec/jbig2/JBig2_HuffmanTable.h +++ b/core/src/fxcodec/jbig2/JBig2_HuffmanTable.h @@ -14,7 +14,7 @@ class CJBig2_HuffmanTable { public: CJBig2_HuffmanTable(const JBig2TableLine* pTable, int nLines, FX_BOOL bHTOOB); - CJBig2_HuffmanTable(CJBig2_BitStream* pStream); + explicit CJBig2_HuffmanTable(CJBig2_BitStream* pStream); ~CJBig2_HuffmanTable(); @@ -24,13 +24,13 @@ class CJBig2_HuffmanTable { int parseFromCodedBuffer(CJBig2_BitStream* pStream); - FX_BOOL isOK() { return m_bOK; } + FX_BOOL isOK() const { return m_bOK; } private: void init(); FX_BOOL HTOOB; - int NTEMP; + FX_DWORD NTEMP; int* CODES; int* PREFLEN; int* RANGELEN; |