From 57cb5447d68c01eddba0618c3a8fe450b180f917 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 1 Sep 2017 11:14:18 -0400 Subject: Adjust loops in preperation for FX_STRSIZE int->size_t Adjust loop conditions and behaviours in preperation for convering the underlying type of FX_STRSIZE to size_t. These changes are not dependent on the type switch occuring, so can be landed before hand. BUG=pdfium:828 Change-Id: I5f950c99c10e5ef0836959e3b1dd2e09f8f5afc0 Reviewed-on: https://pdfium-review.googlesource.com/12750 Commit-Queue: Ryan Harrison Reviewed-by: Henrique Nakashima --- core/fpdfapi/font/cpdf_cmap.cpp | 46 ++++++++++++++++---------------------- core/fpdftext/cpdf_linkextract.cpp | 12 +++++----- 2 files changed, 25 insertions(+), 33 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/font/cpdf_cmap.cpp b/core/fpdfapi/font/cpdf_cmap.cpp index 7b88346d64..9e8c48bb27 100644 --- a/core/fpdfapi/font/cpdf_cmap.cpp +++ b/core/fpdfapi/font/cpdf_cmap.cpp @@ -184,48 +184,43 @@ const PredefinedCMap g_PredefinedCMaps[] = { int CheckFourByteCodeRange(uint8_t* codes, FX_STRSIZE size, const std::vector& ranges) { - int iSeg = pdfium::CollectionSize(ranges) - 1; - while (iSeg >= 0) { - if (ranges[iSeg].m_CharSize < size) { - --iSeg; + for (size_t i = ranges.size(); i > 0; i--) { + size_t seg = i - 1; + if (ranges[seg].m_CharSize < size) continue; - } - int iChar = 0; + FX_STRSIZE iChar = 0; while (iChar < size) { - if (codes[iChar] < ranges[iSeg].m_Lower[iChar] || - codes[iChar] > ranges[iSeg].m_Upper[iChar]) { + if (codes[iChar] < ranges[seg].m_Lower[iChar] || + codes[iChar] > ranges[seg].m_Upper[iChar]) { break; } ++iChar; } - if (iChar == ranges[iSeg].m_CharSize) + if (iChar == ranges[seg].m_CharSize) return 2; if (iChar) - return (size == ranges[iSeg].m_CharSize) ? 2 : 1; - iSeg--; + return (size == ranges[seg].m_CharSize) ? 2 : 1; } return 0; } -int GetFourByteCharSizeImpl(uint32_t charcode, - const std::vector& ranges) { +size_t GetFourByteCharSizeImpl( + uint32_t charcode, + const std::vector& ranges) { if (ranges.empty()) return 1; uint8_t codes[4]; codes[0] = codes[1] = 0x00; - codes[2] = (uint8_t)(charcode >> 8 & 0xFF); - codes[3] = (uint8_t)charcode; - FX_STRSIZE offset = 0; - int size = 4; - for (int i = 0; i < 4; ++i) { - int iSeg = pdfium::CollectionSize(ranges) - 1; - while (iSeg >= 0) { - if (ranges[iSeg].m_CharSize < size) { - --iSeg; + codes[2] = static_cast(charcode >> 8 & 0xFF); + codes[3] = static_cast(charcode); + for (FX_STRSIZE offset = 0; offset < 4; offset++) { + FX_STRSIZE size = 4 - offset; + for (size_t j = 0; j < ranges.size(); j++) { + size_t iSeg = (ranges.size() - 1) - j; + if (ranges[iSeg].m_CharSize < size) continue; - } - int iChar = 0; + FX_STRSIZE iChar = 0; while (iChar < size) { if (codes[offset + iChar] < ranges[iSeg].m_Lower[iChar] || codes[offset + iChar] > ranges[iSeg].m_Upper[iChar]) { @@ -235,10 +230,7 @@ int GetFourByteCharSizeImpl(uint32_t charcode, } if (iChar == ranges[iSeg].m_CharSize) return size; - --iSeg; } - --size; - ++offset; } return 1; } diff --git a/core/fpdftext/cpdf_linkextract.cpp b/core/fpdftext/cpdf_linkextract.cpp index 880a4ceb92..a5eafe689a 100644 --- a/core/fpdftext/cpdf_linkextract.cpp +++ b/core/fpdftext/cpdf_linkextract.cpp @@ -245,24 +245,24 @@ bool CPDF_LinkExtract::CheckMailLink(CFX_WideString* str) { // Check the local part. FX_STRSIZE pPos = aPos.value(); // Used to track the position of '@' or '.'. - for (FX_STRSIZE i = aPos.value() - 1; i >= 0; i--) { - wchar_t ch = (*str)[i]; + for (FX_STRSIZE i = aPos.value(); i > 0; i--) { + wchar_t ch = (*str)[i - 1]; if (ch == L'_' || ch == L'-' || FXSYS_iswalnum(ch)) continue; - if (ch != L'.' || i == pPos - 1 || i == 0) { - if (i == aPos.value() - 1) { + if (ch != L'.' || i == pPos || i == 1) { + if (i == aPos.value()) { // There is '.' or invalid char before '@'. return false; } // End extracting for other invalid chars, '.' at the beginning, or // consecutive '.'. - FX_STRSIZE removed_len = i == pPos - 1 ? i + 2 : i + 1; + FX_STRSIZE removed_len = i == pPos ? i + 1 : i; *str = str->Right(str->GetLength() - removed_len); break; } // Found a valid '.'. - pPos = i; + pPos = i - 1; } // Check the domain name part. -- cgit v1.2.3