diff options
author | Wei Li <weili@chromium.org> | 2016-03-28 10:33:33 -0700 |
---|---|---|
committer | Wei Li <weili@chromium.org> | 2016-03-28 10:33:33 -0700 |
commit | 8940993efffaaf432320509555dc61122b8b72b2 (patch) | |
tree | 2e9c42a78d96061ae06ee052e8a274ccfb8fcec7 /core | |
parent | b5e8f14e3eefc5da995b332788d3203cee204883 (diff) | |
download | pdfium-8940993efffaaf432320509555dc61122b8b72b2.tar.xz |
Reduce signed/unsigned comparison warnings
The warnings generated by Clang. This is part 1 for some simple cases.
BUG=pdfium:29
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1840483003 .
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_colorspace.cpp | 12 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_textobject.cpp | 15 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_array.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp | 15 | ||||
-rw-r--r-- | core/fpdftext/fpdf_text_int.cpp | 16 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_flate.cpp | 5 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_Context.cpp | 18 | ||||
-rw-r--r-- | core/fxcrt/include/fx_ext.h | 2 | ||||
-rw-r--r-- | core/fxge/ge/fx_ge_font.cpp | 3 | ||||
-rw-r--r-- | core/fxge/ge/fx_ge_fontmap.cpp | 4 |
12 files changed, 51 insertions, 49 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp b/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp index 3add21cfed..213d777ecb 100644 --- a/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_colorspace.cpp @@ -467,7 +467,7 @@ void CPDF_ColorSpace::GetDefaultColor(FX_FLOAT* buf) const { return; } FX_FLOAT min, max; - for (int i = 0; i < m_nComponents; i++) { + for (uint32_t i = 0; i < m_nComponents; i++) { GetDefaultValue(i, buf[i], min, max); } } @@ -490,7 +490,7 @@ void CPDF_ColorSpace::TranslateImageLine(uint8_t* dest_buf, FX_FLOAT* src = srcbuf; FX_FLOAT R, G, B; for (int i = 0; i < pixels; i++) { - for (int j = 0; j < m_nComponents; j++) + for (uint32_t j = 0; j < m_nComponents; j++) if (m_Family == PDFCS_INDEXED) { src[j] = (FX_FLOAT)(*src_buf++); } else { @@ -842,7 +842,7 @@ FX_BOOL CPDF_ICCBasedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { } CPDF_Array* pRanges = pDict->GetArrayBy("Range"); m_pRanges = FX_Alloc2D(FX_FLOAT, m_nComponents, 2); - for (int i = 0; i < m_nComponents * 2; i++) { + for (uint32_t i = 0; i < m_nComponents * 2; i++) { if (pRanges) m_pRanges[i] = pRanges->GetNumberAt(i); else if (i % 2) @@ -918,7 +918,7 @@ void CPDF_ICCBasedCS::TranslateImageLine(uint8_t* pDestBuf, ReverseRGB(pDestBuf, pSrcBuf, pixels); } else if (m_pProfile->m_pTransform) { int nMaxColors = 1; - for (int i = 0; i < m_nComponents; i++) { + for (uint32_t i = 0; i < m_nComponents; i++) { nMaxColors *= 52; } if (m_nComponents > 3 || image_width * image_height < nMaxColors * 3 / 2) { @@ -932,7 +932,7 @@ void CPDF_ICCBasedCS::TranslateImageLine(uint8_t* pDestBuf, for (int i = 0; i < nMaxColors; i++) { uint32_t color = i; uint32_t order = nMaxColors / 52; - for (int c = 0; c < m_nComponents; c++) { + for (uint32_t c = 0; c < m_nComponents; c++) { *pSrc++ = (uint8_t)(color / order * 5); color %= order; order /= 52; @@ -944,7 +944,7 @@ void CPDF_ICCBasedCS::TranslateImageLine(uint8_t* pDestBuf, } for (int i = 0; i < pixels; i++) { int index = 0; - for (int c = 0; c < m_nComponents; c++) { + for (uint32_t c = 0; c < m_nComponents; c++) { index = index * 52 + (*pSrcBuf) / 5; pSrcBuf++; } diff --git a/core/fpdfapi/fpdf_page/cpdf_textobject.cpp b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp index 7ca03b4f05..444101fb9e 100644 --- a/core/fpdfapi/fpdf_page/cpdf_textobject.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp @@ -28,7 +28,7 @@ void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[index]; pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0; pInfo->m_OriginY = 0; - if (pInfo->m_CharCode == -1) { + if (pInfo->m_CharCode == CPDF_Font::kInvalidCharCode) { return; } CPDF_Font* pFont = m_TextState.GetFont(); @@ -54,7 +54,7 @@ int CPDF_TextObject::CountChars() const { } int count = 0; for (int i = 0; i < m_nChars; ++i) - if (m_pCharCodes[i] != (uint32_t)-1) { + if (m_pCharCodes[i] != CPDF_Font::kInvalidCharCode) { ++count; } return count; @@ -70,10 +70,11 @@ void CPDF_TextObject::GetCharInfo(int index, } int count = 0; for (int i = 0; i < m_nChars; ++i) { - if (m_pCharCodes[i] != (uint32_t)-1) { + if (m_pCharCodes[i] != CPDF_Font::kInvalidCharCode) { if (count == index) { charcode = m_pCharCodes[i]; - if (i == m_nChars - 1 || m_pCharCodes[i + 1] != (uint32_t)-1) { + if (i == m_nChars - 1 || + m_pCharCodes[i + 1] != CPDF_Font::kInvalidCharCode) { kerning = 0; } else { kerning = m_pCharPos[i]; @@ -93,7 +94,7 @@ void CPDF_TextObject::GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const { int count = 0; for (int i = 0; i < m_nChars; ++i) { uint32_t charcode = m_pCharCodes[i]; - if (charcode == (uint32_t)-1) { + if (charcode == CPDF_Font::kInvalidCharCode) { continue; } if (count == index) { @@ -156,7 +157,7 @@ void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs, } if (i != nsegs - 1) { m_pCharPos[index - 1] = pKerning[i]; - m_pCharCodes[index++] = (uint32_t)-1; + m_pCharCodes[index++] = CPDF_Font::kInvalidCharCode; } } } else { @@ -206,7 +207,7 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, uint32_t charcode = m_nChars == 1 ? (uint32_t)(uintptr_t)m_pCharCodes : m_pCharCodes[i]; if (i > 0) { - if (charcode == (uint32_t)-1) { + if (charcode == CPDF_Font::kInvalidCharCode) { curpos -= (m_pCharPos[i - 1] * fontsize) / 1000; continue; } diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index f2b7582a01..8bff5445ff 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -48,7 +48,7 @@ uint32_t DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, uint8_t*& dest_buf, uint32_t& dest_size) { if (!pDecoder) { - return static_cast<uint32_t>(-1); + return FX_INVALID_OFFSET; } int ncomps = pDecoder->CountComps(); int bpc = pDecoder->GetBPC(); @@ -57,7 +57,7 @@ uint32_t DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, int pitch = (width * ncomps * bpc + 7) / 8; if (height == 0 || pitch > (1 << 30) / height) { delete pDecoder; - return static_cast<uint32_t>(-1); + return FX_INVALID_OFFSET; } dest_buf = FX_Alloc2D(uint8_t, pitch, height); dest_size = pitch * height; // Safe since checked alloc returned. diff --git a/core/fpdfapi/fpdf_parser/cpdf_array.cpp b/core/fpdfapi/fpdf_parser/cpdf_array.cpp index 69de5bbc26..544469916b 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_array.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_array.cpp @@ -47,7 +47,7 @@ const CPDF_Array* CPDF_Array::AsArray() const { CPDF_Object* CPDF_Array::Clone(FX_BOOL bDirect) const { CPDF_Array* pCopy = new CPDF_Array(); - for (int i = 0; i < GetCount(); i++) { + for (size_t i = 0; i < GetCount(); i++) { CPDF_Object* value = m_Objects.GetAt(i); pCopy->m_Objects.Add(value->Clone(bDirect)); } diff --git a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp index dd2be01311..147ae37ed0 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp @@ -185,7 +185,7 @@ FX_BOOL CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { if (!CanReadFromBitStream(hStream, required_bits)) return FALSE; - for (int j = 0; j < m_dwNSharedObjsArray[i]; j++) + for (uint32_t j = 0; j < m_dwNSharedObjsArray[i]; j++) m_dwIdentifierArray.Add(hStream->GetBits(dwSharedIdBits)); } hStream->ByteAlign(); @@ -385,7 +385,7 @@ IPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage( uint32_t dwIndex = 0; uint32_t dwObjNum = 0; - for (int j = 0; j < m_dwNSharedObjsArray[index]; ++j) { + for (uint32_t j = 0; j < m_dwNSharedObjsArray[index]; ++j) { dwIndex = m_dwIdentifierArray[offset + j]; if (dwIndex >= m_dwSharedObjNumArray.GetSize()) return IPDF_DataAvail::DataNotAvailable; diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp index 219a72507b..346476b62b 100644 --- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp @@ -176,24 +176,21 @@ uint32_t RunLengthDecode(const uint8_t* src_buf, if (src_buf[i] < 128) { old = dest_size; dest_size += src_buf[i] + 1; - if (dest_size < old) { - return static_cast<uint32_t>(-1); - } + if (dest_size < old) + return FX_INVALID_OFFSET; i += src_buf[i] + 2; } else if (src_buf[i] > 128) { old = dest_size; dest_size += 257 - src_buf[i]; - if (dest_size < old) { - return static_cast<uint32_t>(-1); - } + if (dest_size < old) + return FX_INVALID_OFFSET; i += 2; } else { break; } } - if (dest_size >= _STREAM_MAX_SIZE_) { - return static_cast<uint32_t>(-1); - } + if (dest_size >= _STREAM_MAX_SIZE_) + return FX_INVALID_OFFSET; dest_buf = FX_Alloc(uint8_t, dest_size); i = 0; int dest_count = 0; diff --git a/core/fpdftext/fpdf_text_int.cpp b/core/fpdftext/fpdf_text_int.cpp index 349a2cd752..f8f201b547 100644 --- a/core/fpdftext/fpdf_text_int.cpp +++ b/core/fpdftext/fpdf_text_int.cpp @@ -898,7 +898,7 @@ void CPDF_TextPage::ProcessFormObject(CPDF_FormObject* pFormObj, } int CPDF_TextPage::GetCharWidth(uint32_t charCode, CPDF_Font* pFont) const { - if (charCode == -1) + if (charCode == CPDF_Font::kInvalidCharCode) return 0; if (int w = pFont->GetCharWidthF(charCode)) @@ -1149,7 +1149,8 @@ int32_t CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { CPDF_Font* pFont = pTextObj->GetFont(); bExist = FALSE; for (FX_STRSIZE i = 0; i < nItems; i++) { - if (pFont->CharCodeFromUnicode(actText.GetAt(i)) != -1) { + if (pFont->CharCodeFromUnicode(actText.GetAt(i)) != + CPDF_Font::kInvalidCharCode) { bExist = TRUE; break; } @@ -1417,7 +1418,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); uint32_t space_charcode = pFont->CharCodeFromUnicode(' '); FX_FLOAT threshold = 0; - if (space_charcode != -1) { + if (space_charcode != CPDF_Font::kInvalidCharCode) { threshold = fontsize_h * pFont->GetCharWidthF(space_charcode) / 1000; } if (threshold > fontsize_h / 3) { @@ -1439,7 +1440,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { charinfo.m_pTextObj = pTextObj; charinfo.m_Index = m_TextBuf.GetLength(); m_TempTextBuf.AppendChar(TEXT_BLANK_CHAR); - charinfo.m_CharCode = -1; + charinfo.m_CharCode = CPDF_Font::kInvalidCharCode; charinfo.m_Matrix.Copy(formMatrix); matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX, charinfo.m_OriginY); @@ -1448,7 +1449,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { charinfo.m_OriginX, charinfo.m_OriginY); m_TempCharList.push_back(charinfo); } - if (item.m_CharCode == (uint32_t)-1) { + if (item.m_CharCode == CPDF_Font::kInvalidCharCode) { continue; } } @@ -1858,12 +1859,13 @@ FX_BOOL CPDF_TextPage::GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info) { info.m_Index = m_TextBuf.GetLength(); info.m_Unicode = unicode; info.m_pTextObj = NULL; - info.m_CharCode = -1; + info.m_CharCode = CPDF_Font::kInvalidCharCode; info.m_Flag = FPDFTEXT_CHAR_GENERATED; int preWidth = 0; - if (preChar->m_pTextObj && preChar->m_CharCode != (uint32_t)-1) + if (preChar->m_pTextObj && preChar->m_CharCode != -1) { preWidth = GetCharWidth(preChar->m_CharCode, preChar->m_pTextObj->GetFont()); + } FX_FLOAT fFontSize = preChar->m_pTextObj ? preChar->m_pTextObj->GetFontSize() : preChar->m_CharBox.Height(); diff --git a/core/fxcodec/codec/fx_codec_flate.cpp b/core/fxcodec/codec/fx_codec_flate.cpp index e69c017ee7..6961dcccb3 100644 --- a/core/fxcodec/codec/fx_codec_flate.cpp +++ b/core/fxcodec/codec/fx_codec_flate.cpp @@ -9,6 +9,7 @@ #include <algorithm> #include <memory> +#include "core/fxcrt/include/fx_ext.h" #include "core/include/fxcodec/fx_codec.h" #include "core/include/fxcodec/fx_codec_flate.h" #include "third_party/zlib_v128/zlib.h" @@ -942,7 +943,7 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, offset = src_size; int err = decoder->Decode(NULL, dest_size, src_buf, offset, bEarlyChange); if (err || dest_size == 0 || dest_size + 1 < dest_size) { - return static_cast<uint32_t>(-1); + return FX_INVALID_OFFSET; } } { @@ -965,7 +966,7 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, ret = TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); } - return ret ? offset : static_cast<uint32_t>(-1); + return ret ? offset : FX_INVALID_OFFSET; } FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, uint32_t src_size, diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp index 1c316a0dd2..1ff78e121f 100644 --- a/core/fxcodec/jbig2/JBig2_Context.cpp +++ b/core/fxcodec/jbig2/JBig2_Context.cpp @@ -1277,7 +1277,7 @@ JBig2HuffmanCode* CJBig2_Context::decodeSymbolIDHuffmanTable( const size_t kRunCodesSize = 35; int32_t runcodes[kRunCodesSize]; int32_t runcodes_len[kRunCodesSize]; - for (int32_t i = 0; i < kRunCodesSize; ++i) { + for (size_t i = 0; i < kRunCodesSize; ++i) { if (pStream->readNBits(4, &runcodes_len[i]) != 0) return nullptr; } @@ -1288,7 +1288,7 @@ JBig2HuffmanCode* CJBig2_Context::decodeSymbolIDHuffmanTable( int32_t run; int32_t i = 0; while (i < (int)SBNUMSYMS) { - int32_t j; + size_t j; int32_t nVal = 0; int32_t nBits = 0; uint32_t nTemp; @@ -1299,15 +1299,13 @@ JBig2HuffmanCode* CJBig2_Context::decodeSymbolIDHuffmanTable( nVal = (nVal << 1) | nTemp; ++nBits; for (j = 0; j < kRunCodesSize; ++j) { - if (nBits == runcodes_len[j] && nVal == runcodes[j]) { + if (nBits == runcodes_len[j] && nVal == runcodes[j]) break; - } } - if (j < kRunCodesSize) { + if (j < kRunCodesSize) break; - } } - int32_t runcode = j; + int32_t runcode = static_cast<int32_t>(j); if (runcode < 32) { SBSYMCODES.get()[i].codelen = runcode; run = 0; @@ -1327,11 +1325,11 @@ JBig2HuffmanCode* CJBig2_Context::decodeSymbolIDHuffmanTable( if (run > 0) { if (i + run > (int)SBNUMSYMS) return nullptr; - for (j = 0; j < run; ++j) { + for (int32_t k = 0; k < run; ++k) { if (runcode == 32 && i > 0) { - SBSYMCODES.get()[i + j].codelen = SBSYMCODES.get()[i - 1].codelen; + SBSYMCODES.get()[i + k].codelen = SBSYMCODES.get()[i - 1].codelen; } else { - SBSYMCODES.get()[i + j].codelen = 0; + SBSYMCODES.get()[i + k].codelen = 0; } } i += run; diff --git a/core/fxcrt/include/fx_ext.h b/core/fxcrt/include/fx_ext.h index 8492bc96aa..68ae2a3651 100644 --- a/core/fxcrt/include/fx_ext.h +++ b/core/fxcrt/include/fx_ext.h @@ -12,6 +12,8 @@ #include "core/fxcrt/include/fx_basic.h" +#define FX_INVALID_OFFSET static_cast<uint32_t>(-1) + // TODO(thestig) Using unique_ptr with ReleaseDeleter is still not ideal. // Come up or wait for something better. This appears in this file rather // than fx_stream.h due to include ordering restrictions. diff --git a/core/fxge/ge/fx_ge_font.cpp b/core/fxge/ge/fx_ge_font.cpp index 04019a059c..fab5ea28a9 100644 --- a/core/fxge/ge/fx_ge_font.cpp +++ b/core/fxge/ge/fx_ge_font.cpp @@ -4,6 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include "core/fpdfapi/fpdf_font/include/cpdf_font.h" #include "core/fxge/ge/fx_text_int.h" #include "core/include/fxge/fx_freetype.h" #include "core/include/fxge/fx_ge.h" @@ -516,7 +517,7 @@ uint32_t CFX_UnicodeEncodingEx::CharCodeFromUnicode(FX_WCHAR Unicode) const { return Unicode; } } - return static_cast<uint32_t>(-1); + return CPDF_Font::kInvalidCharCode; } CFX_UnicodeEncodingEx* FX_CreateFontEncodingEx(CFX_Font* pFont, diff --git a/core/fxge/ge/fx_ge_fontmap.cpp b/core/fxge/ge/fx_ge_fontmap.cpp index 709ef0031b..c6a6c5c003 100644 --- a/core/fxge/ge/fx_ge_fontmap.cpp +++ b/core/fxge/ge/fx_ge_fontmap.cpp @@ -1329,12 +1329,12 @@ int CFX_FontMapper::GetFaceSize() const { } FX_BOOL CFX_FontMapper::IsBuiltinFace(const FXFT_Face face) const { - for (int i = 0; i < MM_FACE_COUNT; ++i) { + for (size_t i = 0; i < MM_FACE_COUNT; ++i) { if (m_MMFaces[i] == face) { return TRUE; } } - for (int i = 0; i < FOXIT_FACE_COUNT; ++i) { + for (size_t i = 0; i < FOXIT_FACE_COUNT; ++i) { if (m_FoxitFaces[i] == face) { return TRUE; } |