From d4e8f1222ca17b57ac74019b2fc3706e1192645c Mon Sep 17 00:00:00 2001 From: Wei Li Date: Mon, 21 Mar 2016 11:20:44 -0700 Subject: Re-enable several MSVC warnings Re-enable the following warnings: 4245: signed/unsigned conversion mismatch; 4310: cast may truncate data; 4389: operator on signed/unsigned mismatch; 4701: use potentially uninitialized local variable; 4706: assignment within conditional expression Clean up the code to avoid those warnings. BUG=pdfium:29 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1801383002 . --- core/fxcodec/jbig2/JBig2_Context.cpp | 18 ++-- core/fxcodec/jbig2/JBig2_Image.cpp | 195 ++++++++++++++++------------------- core/fxcodec/jbig2/JBig2_TrdProc.cpp | 69 ++++++------- 3 files changed, 130 insertions(+), 152 deletions(-) (limited to 'core/fxcodec/jbig2') diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp index 89157b9bf1..805a102c74 100644 --- a/core/fxcodec/jbig2/JBig2_Context.cpp +++ b/core/fxcodec/jbig2/JBig2_Context.cpp @@ -201,7 +201,7 @@ int32_t CJBig2_Context::getFirstPage(uint8_t* pBuf, } int32_t CJBig2_Context::Continue(IFX_Pause* pPause) { m_ProcessingStatus = FXCODEC_STATUS_DECODE_READY; - int32_t nRet; + int32_t nRet = 0; if (m_PauseStep <= 1) { nRet = decode_EmbedOrgnazation(pPause); } else if (m_PauseStep == 2) { @@ -683,14 +683,14 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { } pTRD->SBRTEMPLATE = (wFlags >> 15) & 0x0001; - uint8_t cSBHUFFFS; - uint8_t cSBHUFFDS; - uint8_t cSBHUFFDT; - uint8_t cSBHUFFRDW; - uint8_t cSBHUFFRDH; - uint8_t cSBHUFFRDX; - uint8_t cSBHUFFRDY; - uint8_t cSBHUFFRSIZE; + uint8_t cSBHUFFFS = 0; + uint8_t cSBHUFFDS = 0; + uint8_t cSBHUFFDT = 0; + uint8_t cSBHUFFRDW = 0; + uint8_t cSBHUFFRDH = 0; + uint8_t cSBHUFFRDX = 0; + uint8_t cSBHUFFRDY = 0; + uint8_t cSBHUFFRSIZE = 0; if (pTRD->SBHUFF == 1) { if (m_pStream->readShortInteger(&wFlags) != 0) return JBIG2_ERROR_TOO_SHORT; diff --git a/core/fxcodec/jbig2/JBig2_Image.cpp b/core/fxcodec/jbig2/JBig2_Image.cpp index 311c38270e..dddc1d29d0 100644 --- a/core/fxcodec/jbig2/JBig2_Image.cpp +++ b/core/fxcodec/jbig2/JBig2_Image.cpp @@ -665,74 +665,46 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, int32_t y, JBig2ComposeOp op, const FX_RECT* pSrcRect) { - int32_t xs0, ys0, xs1, ys1, xd0, yd0, xd1, yd1, xx, yy, w, h, middleDwords, - lineLeft; - FX_DWORD s1, d1, d2, shift, shift1, shift2, tmp, tmp1, tmp2, maskL, maskR, - maskM; - uint8_t *lineSrc, *lineDst, *sp, *dp; - int32_t sw, sh; if (!m_pData) { return FALSE; } + // TODO(weili): Check whether the range check is correct. Should x>=1048576? if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576) { return FALSE; } - sw = pSrcRect->Width(); - sh = pSrcRect->Height(); - if (y < 0) { - ys0 = -y; - } else { - ys0 = 0; - } - if (y + sh > pDst->m_nHeight) { - ys1 = pDst->m_nHeight - y; - } else { - ys1 = sh; - } - if (x < 0) { - xs0 = -x; - } else { - xs0 = 0; - } - if (x + sw > pDst->m_nWidth) { - xs1 = pDst->m_nWidth - x; - } else { - xs1 = sw; - } + int32_t sw = pSrcRect->Width(); + int32_t sh = pSrcRect->Height(); + int32_t ys0 = y < 0 ? -y : 0; + int32_t ys1 = y + sh > pDst->m_nHeight ? pDst->m_nHeight - y : sh; + int32_t xs0 = x < 0 ? -x : 0; + int32_t xs1 = x + sw > pDst->m_nWidth ? pDst->m_nWidth - x : sw; if ((ys0 >= ys1) || (xs0 >= xs1)) { return 0; } - w = xs1 - xs0; - h = ys1 - ys0; - if (y < 0) { - yd0 = 0; - } else { - yd0 = y; - } - if (x < 0) { - xd0 = 0; - } else { - xd0 = x; - } - xd1 = xd0 + w; - yd1 = yd0 + h; - d1 = xd0 & 31; - d2 = xd1 & 31; - s1 = xs0 & 31; - maskL = 0xffffffff >> d1; - maskR = 0xffffffff << ((32 - (xd1 & 31)) % 32); - maskM = maskL & maskR; - lineSrc = m_pData + (pSrcRect->top + ys0) * m_nStride + - (((xs0 + pSrcRect->left) >> 5) << 2); - lineLeft = m_nStride - ((xs0 >> 5) << 2); - lineDst = pDst->m_pData + yd0 * pDst->m_nStride + ((xd0 >> 5) << 2); + int32_t w = xs1 - xs0; + int32_t h = ys1 - ys0; + int32_t yd0 = y < 0 ? 0 : y; + int32_t xd0 = x < 0 ? 0 : x; + int32_t xd1 = xd0 + w; + int32_t yd1 = yd0 + h; + int32_t d1 = xd0 & 31; + int32_t d2 = xd1 & 31; + int32_t s1 = xs0 & 31; + int32_t maskL = 0xffffffff >> d1; + int32_t maskR = 0xffffffff << ((32 - (xd1 & 31)) % 32); + int32_t maskM = maskL & maskR; + uint8_t* lineSrc = m_pData + (pSrcRect->top + ys0) * m_nStride + + (((xs0 + pSrcRect->left) >> 5) << 2); + int32_t lineLeft = m_nStride - ((xs0 >> 5) << 2); + uint8_t* lineDst = pDst->m_pData + yd0 * pDst->m_nStride + ((xd0 >> 5) << 2); if ((xd0 & ~31) == ((xd1 - 1) & ~31)) { if ((xs0 & ~31) == ((xs1 - 1) & ~31)) { if (s1 > d1) { - shift = s1 - d1; - for (yy = yd0; yy < yd1; yy++) { - tmp1 = JBIG2_GETDWORD(lineSrc) << shift; - tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD shift = s1 - d1; + for (int32_t yy = yd0; yy < yd1; yy++) { + FX_DWORD tmp1 = JBIG2_GETDWORD(lineSrc) << shift; + FX_DWORD tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); @@ -758,10 +730,11 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, lineDst += pDst->m_nStride; } } else { - shift = d1 - s1; - for (yy = yd0; yy < yd1; yy++) { - tmp1 = JBIG2_GETDWORD(lineSrc) >> shift; - tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD shift = d1 - s1; + for (int32_t yy = yd0; yy < yd1; yy++) { + FX_DWORD tmp1 = JBIG2_GETDWORD(lineSrc) >> shift; + FX_DWORD tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); @@ -788,12 +761,13 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, } } } else { - shift1 = s1 - d1; - shift2 = 32 - shift1; - for (yy = yd0; yy < yd1; yy++) { - tmp1 = (JBIG2_GETDWORD(lineSrc) << shift1) | - (JBIG2_GETDWORD(lineSrc + 4) >> shift2); - tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD shift1 = s1 - d1; + FX_DWORD shift2 = 32 - shift1; + for (int32_t yy = yd0; yy < yd1; yy++) { + FX_DWORD tmp1 = (JBIG2_GETDWORD(lineSrc) << shift1) | + (JBIG2_GETDWORD(lineSrc + 4) >> shift2); + FX_DWORD tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); @@ -821,16 +795,17 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, } } else { if (s1 > d1) { - shift1 = s1 - d1; - shift2 = 32 - shift1; - middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); - for (yy = yd0; yy < yd1; yy++) { - sp = lineSrc; - dp = lineDst; + FX_DWORD shift1 = s1 - d1; + FX_DWORD shift2 = 32 - shift1; + int32_t middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); + for (int32_t yy = yd0; yy < yd1; yy++) { + uint8_t* sp = lineSrc; + uint8_t* dp = lineDst; if (d1 != 0) { - tmp1 = (JBIG2_GETDWORD(sp) << shift1) | - (JBIG2_GETDWORD(sp + 4) >> shift2); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift1) | + (JBIG2_GETDWORD(sp + 4) >> shift2); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); @@ -855,10 +830,11 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, sp += 4; dp += 4; } - for (xx = 0; xx < middleDwords; xx++) { - tmp1 = (JBIG2_GETDWORD(sp) << shift1) | - (JBIG2_GETDWORD(sp + 4) >> shift2); - tmp2 = JBIG2_GETDWORD(dp); + for (int32_t xx = 0; xx < middleDwords; xx++) { + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift1) | + (JBIG2_GETDWORD(sp + 4) >> shift2); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = tmp1 | tmp2; @@ -884,11 +860,12 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, dp += 4; } if (d2 != 0) { - tmp1 = + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift1) | (((sp + 4) < lineSrc + lineLeft ? JBIG2_GETDWORD(sp + 4) : 0) >> shift2); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); @@ -915,13 +892,14 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, lineDst += pDst->m_nStride; } } else if (s1 == d1) { - middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); - for (yy = yd0; yy < yd1; yy++) { - sp = lineSrc; - dp = lineDst; + int32_t middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); + for (int32_t yy = yd0; yy < yd1; yy++) { + uint8_t* sp = lineSrc; + uint8_t* dp = lineDst; if (d1 != 0) { - tmp1 = JBIG2_GETDWORD(sp); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp1 = JBIG2_GETDWORD(sp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); @@ -946,9 +924,10 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, sp += 4; dp += 4; } - for (xx = 0; xx < middleDwords; xx++) { - tmp1 = JBIG2_GETDWORD(sp); - tmp2 = JBIG2_GETDWORD(dp); + for (int32_t xx = 0; xx < middleDwords; xx++) { + FX_DWORD tmp1 = JBIG2_GETDWORD(sp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = tmp1 | tmp2; @@ -974,8 +953,9 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, dp += 4; } if (d2 != 0) { - tmp1 = JBIG2_GETDWORD(sp); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp1 = JBIG2_GETDWORD(sp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); @@ -1002,15 +982,16 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, lineDst += pDst->m_nStride; } } else { - shift1 = d1 - s1; - shift2 = 32 - shift1; - middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); - for (yy = yd0; yy < yd1; yy++) { - sp = lineSrc; - dp = lineDst; + FX_DWORD shift1 = d1 - s1; + FX_DWORD shift2 = 32 - shift1; + int32_t middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); + for (int32_t yy = yd0; yy < yd1; yy++) { + uint8_t* sp = lineSrc; + uint8_t* dp = lineDst; if (d1 != 0) { - tmp1 = JBIG2_GETDWORD(sp) >> shift1; - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp1 = JBIG2_GETDWORD(sp) >> shift1; + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); @@ -1034,10 +1015,11 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, dp[3] = (uint8_t)tmp; dp += 4; } - for (xx = 0; xx < middleDwords; xx++) { - tmp1 = (JBIG2_GETDWORD(sp) << shift2) | - ((JBIG2_GETDWORD(sp + 4)) >> shift1); - tmp2 = JBIG2_GETDWORD(dp); + for (int32_t xx = 0; xx < middleDwords; xx++) { + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift2) | + ((JBIG2_GETDWORD(sp + 4)) >> shift1); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = tmp1 | tmp2; @@ -1063,11 +1045,12 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, dp += 4; } if (d2 != 0) { - tmp1 = + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift2) | (((sp + 4) < lineSrc + lineLeft ? JBIG2_GETDWORD(sp + 4) : 0) >> shift1); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.cpp b/core/fxcodec/jbig2/JBig2_TrdProc.cpp index 401249e3f2..1a078a1592 100644 --- a/core/fxcodec/jbig2/JBig2_TrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_TrdProc.cpp @@ -15,48 +15,39 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, JBig2ArithCtx* grContext) { - int32_t STRIPT, FIRSTS; - FX_DWORD NINSTANCES; - int32_t DT, DFS, CURS; - int32_t SI, TI; - CJBig2_Image* IBI; - FX_DWORD WI, HI; - int32_t IDS; - FX_BOOL RI; - int32_t RDWI, RDHI, RDXI, RDYI; - CJBig2_Image* IBOI; - FX_DWORD WOI, HOI; - FX_BOOL bFirst; - FX_DWORD nTmp; - int32_t nVal, nBits; std::unique_ptr pHuffmanDecoder( new CJBig2_HuffmanDecoder(pStream)); std::unique_ptr SBREG(new CJBig2_Image(SBW, SBH)); SBREG->fill(SBDEFPIXEL); + int32_t STRIPT; if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &STRIPT) != 0) return nullptr; STRIPT *= SBSTRIPS; STRIPT = -STRIPT; - FIRSTS = 0; - NINSTANCES = 0; + FX_DWORD NINSTANCES = 0; while (NINSTANCES < SBNUMINSTANCES) { + int32_t DT; if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &DT) != 0) return nullptr; DT *= SBSTRIPS; STRIPT = STRIPT + DT; - bFirst = TRUE; + bool bFirst = true; + int32_t FIRSTS = 0; + int32_t CURS = 0; for (;;) { if (bFirst) { + int32_t DFS; if (pHuffmanDecoder->decodeAValue(SBHUFFFS, &DFS) != 0) return nullptr; FIRSTS = FIRSTS + DFS; CURS = FIRSTS; - bFirst = FALSE; + bFirst = false; } else { - nVal = pHuffmanDecoder->decodeAValue(SBHUFFDS, &IDS); + int32_t IDS; + int32_t nVal = pHuffmanDecoder->decodeAValue(SBHUFFDS, &IDS); if (nVal == JBIG2_OOB) { break; } else if (nVal != 0) { @@ -67,20 +58,22 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, } uint8_t CURT = 0; if (SBSTRIPS != 1) { - nTmp = 1; + FX_DWORD nTmp = 1; while ((FX_DWORD)(1 << nTmp) < SBSTRIPS) { nTmp++; } + int32_t nVal; if (pStream->readNBits(nTmp, &nVal) != 0) return nullptr; CURT = nVal; } - TI = STRIPT + CURT; - nVal = 0; - nBits = 0; + int32_t TI = STRIPT + CURT; + int32_t nVal = 0; + int32_t nBits = 0; FX_DWORD IDI; for (;;) { + FX_DWORD nTmp; if (pStream->read1Bit(&nTmp) != 0) return nullptr; @@ -96,16 +89,18 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, break; } } - if (SBREFINE == 0) { - RI = 0; - } else { - if (pStream->read1Bit(&RI) != 0) { - return nullptr; - } + FX_BOOL RI = 0; + if (SBREFINE != 0 && pStream->read1Bit(&RI) != 0) { + return nullptr; } + CJBig2_Image* IBI = nullptr; if (RI == 0) { IBI = SBSYMS[IDI]; } else { + int32_t RDWI; + int32_t RDHI; + int32_t RDXI; + int32_t RDYI; if ((pHuffmanDecoder->decodeAValue(SBHUFFRDW, &RDWI) != 0) || (pHuffmanDecoder->decodeAValue(SBHUFFRDH, &RDHI) != 0) || (pHuffmanDecoder->decodeAValue(SBHUFFRDX, &RDXI) != 0) || @@ -114,13 +109,13 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, return nullptr; } pStream->alignByte(); - nTmp = pStream->getOffset(); - IBOI = SBSYMS[IDI]; + FX_DWORD nTmp = pStream->getOffset(); + CJBig2_Image* IBOI = SBSYMS[IDI]; if (!IBOI) return nullptr; - WOI = IBOI->m_nWidth; - HOI = IBOI->m_nHeight; + FX_DWORD WOI = IBOI->m_nWidth; + FX_DWORD HOI = IBOI->m_nHeight; if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) return nullptr; @@ -155,8 +150,8 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, if (!IBI) { continue; } - WI = IBI->m_nWidth; - HI = IBI->m_nHeight; + FX_DWORD WI = IBI->m_nWidth; + FX_DWORD HI = IBI->m_nHeight; if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPRIGHT) || (REFCORNER == JBIG2_CORNER_BOTTOMRIGHT))) { CURS = CURS + WI - 1; @@ -164,7 +159,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, (REFCORNER == JBIG2_CORNER_BOTTOMRIGHT))) { CURS = CURS + HI - 1; } - SI = CURS; + int32_t SI = CURS; if (TRANSPOSED == 0) { switch (REFCORNER) { case JBIG2_CORNER_TOPLEFT: @@ -277,7 +272,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, int32_t FIRSTS = 0; FX_DWORD NINSTANCES = 0; while (NINSTANCES < SBNUMINSTANCES) { - int32_t CURS; + int32_t CURS = 0; int32_t DT; pIADT->decode(pArithDecoder, &DT); DT *= SBSTRIPS; -- cgit v1.2.3