diff options
author | Ryan Harrison <rharrison@chromium.org> | 2017-09-27 10:53:11 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-09-27 16:11:38 +0000 |
commit | 875e98c581952478f3a3ccef9b2f2e3ed06c5346 (patch) | |
tree | 8e0d7e032056bf4c73d6da43c0f3ce4eadb74dfd /core | |
parent | cc3a3ee3ebcc1baabdfa7ffca5876dbbfa3980c1 (diff) | |
download | pdfium-875e98c581952478f3a3ccef9b2f2e3ed06c5346.tar.xz |
Remove FX_STRSIZE and replace with size_t
BUG=pdfium:828
Change-Id: I5c40237433ebabaeabdb43aec9cdf783e41dfe16
Reviewed-on: https://pdfium-review.googlesource.com/13230
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core')
41 files changed, 423 insertions, 443 deletions
diff --git a/core/fpdfapi/font/cpdf_cmap.cpp b/core/fpdfapi/font/cpdf_cmap.cpp index 54f7b34ca0..1eabfff866 100644 --- a/core/fpdfapi/font/cpdf_cmap.cpp +++ b/core/fpdfapi/font/cpdf_cmap.cpp @@ -182,13 +182,13 @@ const PredefinedCMap g_PredefinedCMaps[] = { }; int CheckFourByteCodeRange(uint8_t* codes, - FX_STRSIZE size, + size_t size, const std::vector<CPDF_CMap::CodeRange>& ranges) { for (size_t i = ranges.size(); i > 0; i--) { size_t seg = i - 1; if (ranges[seg].m_CharSize < size) continue; - FX_STRSIZE iChar = 0; + size_t iChar = 0; while (iChar < size) { if (codes[iChar] < ranges[seg].m_Lower[iChar] || codes[iChar] > ranges[seg].m_Upper[iChar]) { @@ -214,13 +214,13 @@ size_t GetFourByteCharSizeImpl( codes[0] = codes[1] = 0x00; codes[2] = static_cast<uint8_t>(charcode >> 8 & 0xFF); codes[3] = static_cast<uint8_t>(charcode); - for (FX_STRSIZE offset = 0; offset < 4; offset++) { - FX_STRSIZE size = 4 - offset; + for (size_t offset = 0; offset < 4; offset++) { + size_t 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; - FX_STRSIZE iChar = 0; + size_t iChar = 0; while (iChar < size) { if (codes[offset + iChar] < ranges[iSeg].m_Lower[iChar] || codes[offset + iChar] > ranges[iSeg].m_Upper[iChar]) { diff --git a/core/fpdfapi/font/cpdf_cmap.h b/core/fpdfapi/font/cpdf_cmap.h index 6e90c3936b..493d30097a 100644 --- a/core/fpdfapi/font/cpdf_cmap.h +++ b/core/fpdfapi/font/cpdf_cmap.h @@ -36,7 +36,7 @@ class CPDF_CMap : public Retainable { }; struct CodeRange { - FX_STRSIZE m_CharSize; + size_t m_CharSize; uint8_t m_Lower[4]; uint8_t m_Upper[4]; }; diff --git a/core/fpdfapi/font/cpdf_cmapparser.cpp b/core/fpdfapi/font/cpdf_cmapparser.cpp index f7d4dc1c33..a5d79776ba 100644 --- a/core/fpdfapi/font/cpdf_cmapparser.cpp +++ b/core/fpdfapi/font/cpdf_cmapparser.cpp @@ -141,8 +141,7 @@ uint32_t CPDF_CMapParser::CMap_GetCode(const ByteStringView& word) { return 0; pdfium::base::CheckedNumeric<uint32_t> num = 0; if (word[0] == '<') { - for (FX_STRSIZE i = 1; i < word.GetLength() && std::isxdigit(word[i]); - ++i) { + for (size_t i = 1; i < word.GetLength() && std::isxdigit(word[i]); ++i) { num = num * 16 + FXSYS_HexCharToInt(word[i]); if (!num.IsValid()) return 0; @@ -150,7 +149,7 @@ uint32_t CPDF_CMapParser::CMap_GetCode(const ByteStringView& word) { return num.ValueOrDie(); } - for (FX_STRSIZE i = 0; i < word.GetLength() && std::isdigit(word[i]); ++i) { + for (size_t i = 0; i < word.GetLength() && std::isdigit(word[i]); ++i) { num = num * 10 + FXSYS_DecimalCharToInt(static_cast<wchar_t>(word[i])); if (!num.IsValid()) return 0; @@ -165,7 +164,7 @@ bool CPDF_CMapParser::CMap_GetCodeRange(CPDF_CMap::CodeRange& range, if (first.GetLength() == 0 || first[0] != '<') return false; - FX_STRSIZE i; + size_t i; for (i = 1; i < first.GetLength(); ++i) { if (first[i] == '>') { break; @@ -182,7 +181,7 @@ bool CPDF_CMapParser::CMap_GetCodeRange(CPDF_CMap::CodeRange& range, FXSYS_HexCharToInt(digit1) * 16 + FXSYS_HexCharToInt(digit2); } - FX_STRSIZE size = second.GetLength(); + size_t size = second.GetLength(); for (i = 0; i < range.m_CharSize; ++i) { uint8_t digit1 = (i * 2 + 1 < size) ? second[i * 2 + 1] : '0'; uint8_t digit2 = (i * 2 + 2 < size) ? second[i * 2 + 2] : '0'; diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp index 4c08336e3a..d722c22fb5 100644 --- a/core/fpdfapi/page/cpdf_image.cpp +++ b/core/fpdfapi/page/cpdf_image.cpp @@ -171,7 +171,7 @@ void CPDF_Image::SetImage(const RetainPtr<CFX_DIBitmap>& pBitmap) { pDict->SetNewFor<CPDF_Number>("Height", BitmapHeight); const int32_t bpp = pBitmap->GetBPP(); - FX_STRSIZE dest_pitch = 0; + size_t dest_pitch = 0; bool bCopyWithoutAlpha = true; if (bpp == 1) { int32_t reset_a = 0; @@ -285,7 +285,7 @@ void CPDF_Image::SetImage(const RetainPtr<CFX_DIBitmap>& pBitmap) { int32_t src_pitch = pBitmap->GetPitch(); uint8_t* dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight); // Safe as checked alloc returned. - FX_STRSIZE dest_size = dest_pitch * BitmapHeight; + size_t dest_size = dest_pitch * BitmapHeight; uint8_t* pDest = dest_buf; if (bCopyWithoutAlpha) { for (int32_t i = 0; i < BitmapHeight; i++) { diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp index e9320cbc6f..aa1d227de0 100644 --- a/core/fpdfapi/page/cpdf_streamparser.cpp +++ b/core/fpdfapi/page/cpdf_streamparser.cpp @@ -34,7 +34,7 @@ namespace { const uint32_t kMaxNestedParsingLevel = 512; const uint32_t kMaxWordBuffer = 256; -const FX_STRSIZE kMaxStringLength = 32767; +const size_t kMaxStringLength = 32767; uint32_t DecodeAllScanlines(std::unique_ptr<CCodec_ScanlineDecoder> pDecoder, uint8_t** dest_buf, @@ -478,9 +478,9 @@ ByteString CPDF_StreamParser::ReadString() { case 0: if (ch == ')') { if (parlevel == 0) { - return ByteString(buf.str().c_str(), - std::min(static_cast<FX_STRSIZE>(buf.tellp()), - kMaxStringLength)); + return ByteString( + buf.str().c_str(), + std::min(static_cast<size_t>(buf.tellp()), kMaxStringLength)); } parlevel--; buf << ')'; @@ -557,7 +557,7 @@ ByteString CPDF_StreamParser::ReadString() { return ByteString( buf.str().c_str(), - std::min(static_cast<FX_STRSIZE>(buf.tellp()), kMaxStringLength)); + std::min(static_cast<size_t>(buf.tellp()), kMaxStringLength)); } ByteString CPDF_StreamParser::ReadHexString() { @@ -590,7 +590,7 @@ ByteString CPDF_StreamParser::ReadHexString() { return ByteString( buf.str().c_str(), - std::min(static_cast<FX_STRSIZE>(buf.tellp()), kMaxStringLength)); + std::min(static_cast<size_t>(buf.tellp()), kMaxStringLength)); } bool CPDF_StreamParser::PositionIsInBounds() const { diff --git a/core/fpdfapi/parser/cpdf_simple_parser.cpp b/core/fpdfapi/parser/cpdf_simple_parser.cpp index d800796d58..5358b183d8 100644 --- a/core/fpdfapi/parser/cpdf_simple_parser.cpp +++ b/core/fpdfapi/parser/cpdf_simple_parser.cpp @@ -103,7 +103,7 @@ ByteStringView CPDF_SimpleParser::GetWord() { m_dwCurPos++; } return ByteStringView(pStart, - (FX_STRSIZE)(m_dwCurPos - (pStart - m_pData))); + static_cast<size_t>(m_dwCurPos - (pStart - m_pData))); } if (dwSize == 1 && pStart[0] == '(') { int level = 1; @@ -131,7 +131,7 @@ ByteStringView CPDF_SimpleParser::GetWord() { m_dwCurPos++; } return ByteStringView(pStart, - (FX_STRSIZE)(m_dwCurPos - (pStart - m_pData))); + static_cast<size_t>(m_dwCurPos - (pStart - m_pData))); } return ByteStringView(pStart, dwSize); } diff --git a/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp index ae30959013..9ab4958825 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp @@ -81,7 +81,7 @@ TEST(fpdf_parser_decode, EncodeText) { struct EncodeTestData { const wchar_t* input; const char* expected_output; - FX_STRSIZE expected_length; + size_t expected_length; } test_data[] = { // Empty src string. {L"", "", 0}, @@ -103,7 +103,7 @@ TEST(fpdf_parser_decode, EncodeText) { ASSERT_EQ(test_case.expected_length, output.GetLength()) << "for case " << i; const char* str_ptr = output.c_str(); - for (FX_STRSIZE j = 0; j < test_case.expected_length; ++j) { + for (size_t j = 0; j < test_case.expected_length; ++j) { EXPECT_EQ(test_case.expected_output[j], str_ptr[j]) << "for case " << i << " char " << j; } diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp index e57f834cee..2185e88ff6 100644 --- a/core/fpdfapi/parser/fpdf_parser_utility.cpp +++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp @@ -106,7 +106,7 @@ ByteString PDF_NameDecode(const ByteStringView& bstr) { *pDest++ = bstr[i]; } } - result.ReleaseBuffer((FX_STRSIZE)(pDest - pDestStart)); + result.ReleaseBuffer(static_cast<size_t>(pDest - pDestStart)); return result; } diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp index f17e543e70..50db639a4f 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -306,12 +306,12 @@ class CFieldNameExtractor { m_pEnd = m_pCur + m_FullName.GetLength(); } - void GetNext(const wchar_t*& pSubName, FX_STRSIZE& size) { + void GetNext(const wchar_t*& pSubName, size_t& size) { pSubName = m_pCur; while (m_pCur < m_pEnd && m_pCur[0] != L'.') m_pCur++; - size = (FX_STRSIZE)(m_pCur - pSubName); + size = static_cast<size_t>(m_pCur - pSubName); if (m_pCur < m_pEnd && m_pCur[0] == L'.') m_pCur++; } @@ -376,7 +376,7 @@ int CompareFieldName(const WideString& name1, const WideString& name2) { if (name1.GetLength() == name2.GetLength()) return name1 == name2 ? 1 : 0; - FX_STRSIZE i = 0; + size_t i = 0; while (ptr1[i] == ptr2[i]) i++; if (i == name1.GetLength()) @@ -509,7 +509,7 @@ bool CFieldTree::SetField(const WideString& full_name, CFieldNameExtractor name_extractor(full_name); const wchar_t* pName; - FX_STRSIZE nLength; + size_t nLength; name_extractor.GetNext(pName, nLength); Node* pNode = &m_Root; Node* pLast = nullptr; @@ -537,7 +537,7 @@ CPDF_FormField* CFieldTree::GetField(const WideString& full_name) { CFieldNameExtractor name_extractor(full_name); const wchar_t* pName; - FX_STRSIZE nLength; + size_t nLength; name_extractor.GetNext(pName, nLength); Node* pNode = &m_Root; Node* pLast = nullptr; @@ -556,7 +556,7 @@ CFieldTree::Node* CFieldTree::FindNode(const WideString& full_name) { CFieldNameExtractor name_extractor(full_name); const wchar_t* pName; - FX_STRSIZE nLength; + size_t nLength; name_extractor.GetNext(pName, nLength); Node* pNode = &m_Root; Node* pLast = nullptr; diff --git a/core/fpdftext/cpdf_linkextract.cpp b/core/fpdftext/cpdf_linkextract.cpp index 91116711e6..3a38343721 100644 --- a/core/fpdftext/cpdf_linkextract.cpp +++ b/core/fpdftext/cpdf_linkextract.cpp @@ -19,9 +19,7 @@ namespace { // |end|. The purpose of this function is to separate url from the surrounding // context characters, we do not intend to fully validate the url. |str| // contains lower case characters only. -FX_STRSIZE FindWebLinkEnding(const WideString& str, - FX_STRSIZE start, - FX_STRSIZE end) { +size_t FindWebLinkEnding(const WideString& str, size_t start, size_t end) { if (str.Contains(L'/', start)) { // When there is a path and query after '/', most ASCII chars are allowed. // We don't sanitize in this case. @@ -37,8 +35,8 @@ FX_STRSIZE FindWebLinkEnding(const WideString& str, if (result.has_value()) { end = result.value(); if (end > start + 1) { // Has content inside brackets. - FX_STRSIZE len = str.GetLength(); - FX_STRSIZE off = end + 1; + size_t len = str.GetLength(); + size_t off = end + 1; if (off < len && str[off] == L':') { off++; while (off < len && str[off] >= L'0' && str[off] <= L'9') @@ -69,9 +67,9 @@ FX_STRSIZE FindWebLinkEnding(const WideString& str, // |end| if characters were removed. void TrimBackwardsToChar(const WideString& str, wchar_t charToFind, - FX_STRSIZE start, - FX_STRSIZE* end) { - for (FX_STRSIZE pos = *end; pos >= start; pos--) { + size_t start, + size_t* end) { + for (size_t pos = *end; pos >= start; pos--) { if (str[pos] == charToFind) { *end = pos - 1; break; @@ -83,10 +81,10 @@ void TrimBackwardsToChar(const WideString& str, // |start| and |end| in |str|. Matches a closing bracket or quote for each // opening character and, if present, removes everything afterwards. Returns the // new end position for the string. -FX_STRSIZE TrimExternalBracketsFromWebLink(const WideString& str, - FX_STRSIZE start, - FX_STRSIZE end) { - for (FX_STRSIZE pos = 0; pos < start; pos++) { +size_t TrimExternalBracketsFromWebLink(const WideString& str, + size_t start, + size_t end) { + for (size_t pos = 0; pos < start; pos++) { if (str[pos] == '(') { TrimBackwardsToChar(str, ')', start, &end); } else if (str[pos] == '[') { @@ -191,25 +189,25 @@ bool CPDF_LinkExtract::CheckWebLink(WideString* strBeCheck, int32_t* nStart, int32_t* nCount) { static const wchar_t kHttpScheme[] = L"http"; - static const FX_STRSIZE kHttpSchemeLen = FXSYS_len(kHttpScheme); + static const size_t kHttpSchemeLen = FXSYS_len(kHttpScheme); static const wchar_t kWWWAddrStart[] = L"www."; - static const FX_STRSIZE kWWWAddrStartLen = FXSYS_len(kWWWAddrStart); + static const size_t kWWWAddrStartLen = FXSYS_len(kWWWAddrStart); WideString str = *strBeCheck; str.MakeLower(); - FX_STRSIZE len = str.GetLength(); + size_t len = str.GetLength(); // First, try to find the scheme. auto start = str.Find(kHttpScheme); if (start.has_value()) { - FX_STRSIZE off = start.value() + kHttpSchemeLen; // move after "http". + size_t off = start.value() + kHttpSchemeLen; // move after "http". if (len > off + 4) { // At least "://<char>" follows. if (str[off] == L's') // "https" scheme is accepted. off++; if (str[off] == L':' && str[off + 1] == L'/' && str[off + 2] == L'/') { off += 3; - FX_STRSIZE end = TrimExternalBracketsFromWebLink(str, start.value(), - str.GetLength() - 1); + size_t end = TrimExternalBracketsFromWebLink(str, start.value(), + str.GetLength() - 1); end = FindWebLinkEnding(str, off, end); if (end > off) { // Non-empty host name. *nStart = start.value(); @@ -224,8 +222,8 @@ bool CPDF_LinkExtract::CheckWebLink(WideString* strBeCheck, // When there is no scheme, try to find url starting with "www.". start = str.Find(kWWWAddrStart); if (start.has_value() && len > start.value() + kWWWAddrStartLen) { - FX_STRSIZE end = TrimExternalBracketsFromWebLink(str, start.value(), - str.GetLength() - 1); + size_t end = TrimExternalBracketsFromWebLink(str, start.value(), + str.GetLength() - 1); end = FindWebLinkEnding(str, start.value(), end); if (end > start.value() + kWWWAddrStartLen) { *nStart = start.value(); @@ -244,8 +242,8 @@ bool CPDF_LinkExtract::CheckMailLink(WideString* str) { return false; // Check the local part. - FX_STRSIZE pPos = aPos.value(); // Used to track the position of '@' or '.'. - for (FX_STRSIZE i = aPos.value(); i > 0; i--) { + size_t pPos = aPos.value(); // Used to track the position of '@' or '.'. + for (size_t i = aPos.value(); i > 0; i--) { wchar_t ch = (*str)[i - 1]; if (ch == L'_' || ch == L'-' || FXSYS_iswalnum(ch)) continue; @@ -257,7 +255,7 @@ bool CPDF_LinkExtract::CheckMailLink(WideString* str) { } // End extracting for other invalid chars, '.' at the beginning, or // consecutive '.'. - FX_STRSIZE removed_len = i == pPos ? i + 1 : i; + size_t removed_len = i == pPos ? i + 1 : i; *str = str->Right(str->GetLength() - removed_len); break; } @@ -279,16 +277,16 @@ bool CPDF_LinkExtract::CheckMailLink(WideString* str) { return false; // Validate all other chars in domain name. - FX_STRSIZE nLen = str->GetLength(); + size_t nLen = str->GetLength(); pPos = 0; // Used to track the position of '.'. - for (FX_STRSIZE i = aPos.value() + 1; i < nLen; i++) { + for (size_t i = aPos.value() + 1; i < nLen; i++) { wchar_t wch = (*str)[i]; if (wch == L'-' || FXSYS_iswalnum(wch)) continue; if (wch != L'.' || i == pPos + 1) { // Domain name should end before invalid char. - FX_STRSIZE host_end = i == pPos + 1 ? i - 2 : i - 1; + size_t host_end = i == pPos + 1 ? i - 2 : i - 1; if (pPos > 0 && host_end - aPos.value() >= 3) { // Trim the ending invalid chars if there is at least one '.' and name. *str = str->Left(host_end + 1); diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index f73793cd72..fd33fb2f2f 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -66,7 +66,7 @@ float CalculateBaseSpace(const CPDF_TextObject* pTextObj, return baseSpace; } -FX_STRSIZE Unicode_GetNormalization(wchar_t wch, wchar_t* pDst) { +size_t Unicode_GetNormalization(wchar_t wch, wchar_t* pDst) { wch = wch & 0xFFFF; wchar_t wFind = g_UnicodeData_Normalization[wch]; if (!wFind) { @@ -93,7 +93,7 @@ FX_STRSIZE Unicode_GetNormalization(wchar_t wch, wchar_t* pDst) { while (n--) *pDst++ = *pMap++; } - return (FX_STRSIZE)wFind; + return static_cast<size_t>(wFind); } float MaskPercentFilled(const std::vector<bool>& mask, @@ -649,11 +649,11 @@ void CPDF_TextPage::AddCharInfoByLRDirection(wchar_t wChar, info.m_Index = m_TextBuf.GetLength(); if (wChar >= 0xFB00 && wChar <= 0xFB06) { wchar_t* pDst = nullptr; - FX_STRSIZE nCount = Unicode_GetNormalization(wChar, pDst); + size_t nCount = Unicode_GetNormalization(wChar, pDst); if (nCount >= 1) { pDst = FX_Alloc(wchar_t, nCount); Unicode_GetNormalization(wChar, pDst); - for (FX_STRSIZE nIndex = 0; nIndex < nCount; nIndex++) { + for (size_t nIndex = 0; nIndex < nCount; nIndex++) { PAGECHAR_INFO info2 = info; info2.m_Unicode = pDst[nIndex]; info2.m_Flag = FPDFTEXT_CHAR_PIECE; @@ -679,11 +679,11 @@ void CPDF_TextPage::AddCharInfoByRLDirection(wchar_t wChar, info.m_Index = m_TextBuf.GetLength(); wChar = FX_GetMirrorChar(wChar); wchar_t* pDst = nullptr; - FX_STRSIZE nCount = Unicode_GetNormalization(wChar, pDst); + size_t nCount = Unicode_GetNormalization(wChar, pDst); if (nCount >= 1) { pDst = FX_Alloc(wchar_t, nCount); Unicode_GetNormalization(wChar, pDst); - for (FX_STRSIZE nIndex = 0; nIndex < nCount; nIndex++) { + for (size_t nIndex = 0; nIndex < nCount; nIndex++) { PAGECHAR_INFO info2 = info; info2.m_Unicode = pDst[nIndex]; info2.m_Flag = FPDFTEXT_CHAR_PIECE; @@ -704,7 +704,7 @@ void CPDF_TextPage::CloseTempLine() { WideString str = m_TempTextBuf.MakeString(); bool bPrevSpace = false; - for (FX_STRSIZE i = 0; i < str.GetLength(); i++) { + for (size_t i = 0; i < str.GetLength(); i++) { if (str[i] != ' ') { bPrevSpace = false; continue; @@ -838,13 +838,12 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { return FPDFText_MarkedContent::Done; } - FX_STRSIZE nItems = actText.GetLength(); - if (nItems < 1) + if (actText.IsEmpty()) return FPDFText_MarkedContent::Pass; CPDF_Font* pFont = pTextObj->GetFont(); bExist = false; - for (FX_STRSIZE i = 0; i < nItems; i++) { + for (size_t i = 0; i < actText.GetLength(); i++) { if (pFont->CharCodeFromUnicode(actText[i]) != CPDF_Font::kInvalidCharCode) { bExist = true; break; @@ -854,7 +853,7 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { return FPDFText_MarkedContent::Pass; bExist = false; - for (FX_STRSIZE i = 0; i < nItems; i++) { + for (size_t i = 0; i < actText.GetLength(); i++) { wchar_t wChar = actText[i]; if ((wChar > 0x80 && wChar < 0xFFFD) || (wChar <= 0x80 && isprint(wChar))) { bExist = true; @@ -883,15 +882,14 @@ void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { if (pDict) actText = pDict->GetUnicodeTextFor("ActualText"); } - FX_STRSIZE nItems = actText.GetLength(); - if (nItems < 1) + if (actText.IsEmpty()) return; CPDF_Font* pFont = pTextObj->GetFont(); CFX_Matrix matrix = pTextObj->GetTextMatrix(); matrix.Concat(Obj.m_formMatrix); - for (FX_STRSIZE k = 0; k < nItems; k++) { + for (size_t k = 0; k < actText.GetLength(); k++) { wchar_t wChar = actText[k]; if (wChar <= 0x80 && !isprint(wChar)) wChar = 0x20; diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp index f00b8a9f4d..9f9be202d6 100644 --- a/core/fpdftext/cpdf_textpagefind.cpp +++ b/core/fpdftext/cpdf_textpagefind.cpp @@ -81,7 +81,7 @@ int CPDF_TextPageFind::GetCharIndex(int index) const { bool CPDF_TextPageFind::FindFirst(const WideString& findwhat, int flags, - pdfium::Optional<FX_STRSIZE> startPos) { + pdfium::Optional<size_t> startPos) { if (!m_pTextPage) return false; if (m_strText.IsEmpty() || m_bMatchCase != (flags & FPDFTEXT_MATCHCASE)) @@ -94,7 +94,7 @@ bool CPDF_TextPageFind::FindFirst(const WideString& findwhat, m_IsFind = false; return true; } - FX_STRSIZE len = findwhatStr.GetLength(); + size_t len = findwhatStr.GetLength(); if (!m_bMatchCase) { findwhatStr.MakeLower(); m_strText.MakeLower(); @@ -102,25 +102,24 @@ bool CPDF_TextPageFind::FindFirst(const WideString& findwhat, m_bMatchWholeWord = !!(flags & FPDFTEXT_MATCHWHOLEWORD); m_findNextStart = startPos; if (!startPos.has_value()) { - if (m_strText.GetLength() > 0) + if (!m_strText.IsEmpty()) m_findPreStart = m_strText.GetLength() - 1; } else { m_findPreStart = startPos; } m_csFindWhatArray.clear(); - FX_STRSIZE i = 0; - while (i < len) { + size_t i = 0; + for (i = 0; i < len; ++i) if (findwhatStr[i] != ' ') break; - i++; - } if (i < len) ExtractFindWhat(findwhatStr); else m_csFindWhatArray.push_back(findwhatStr); if (m_csFindWhatArray.empty()) return false; + m_IsFind = true; m_resStart = 0; m_resEnd = -1; @@ -137,14 +136,14 @@ bool CPDF_TextPageFind::FindNext() { m_IsFind = false; return m_IsFind; } - FX_STRSIZE strLen = m_strText.GetLength(); + size_t strLen = m_strText.GetLength(); if (m_findNextStart.value() > strLen - 1) { m_IsFind = false; return m_IsFind; } int nCount = pdfium::CollectionSize<int>(m_csFindWhatArray); - pdfium::Optional<FX_STRSIZE> nResultPos = 0; - FX_STRSIZE nStartPos = m_findNextStart.value(); + pdfium::Optional<size_t> nResultPos = 0; + size_t nStartPos = m_findNextStart.value(); bool bSpaceStart = false; for (int iWord = 0; iWord < nCount; iWord++) { WideString csWord = m_csFindWhatArray[iWord]; @@ -162,18 +161,17 @@ bool CPDF_TextPageFind::FindNext() { } continue; } - FX_STRSIZE endIndex; nResultPos = m_strText.Find(csWord.c_str(), nStartPos); if (!nResultPos.has_value()) { m_IsFind = false; return m_IsFind; } - endIndex = nResultPos.value() + csWord.GetLength() - 1; + size_t endIndex = nResultPos.value() + csWord.GetLength() - 1; if (iWord == 0) m_resStart = nResultPos.value(); bool bMatch = true; if (iWord != 0 && !bSpaceStart) { - FX_STRSIZE PreResEndPos = nStartPos; + size_t PreResEndPos = nStartPos; int curChar = csWord[0]; WideString lastWord = m_csFindWhatArray[iWord - 1]; int lastChar = lastWord[lastWord.GetLength() - 1]; @@ -182,7 +180,7 @@ bool CPDF_TextPageFind::FindNext() { IsIgnoreSpaceCharacter(curChar))) { bMatch = false; } - for (FX_STRSIZE d = PreResEndPos; d < nResultPos.value(); d++) { + for (size_t d = PreResEndPos; d < nResultPos.value(); d++) { wchar_t strInsert = m_strText[d]; if (strInsert != TEXT_LINEFEED_CHAR && strInsert != TEXT_SPACE_CHAR && strInsert != TEXT_RETURN_CHAR && strInsert != 160) { @@ -238,20 +236,21 @@ bool CPDF_TextPageFind::FindPrev() { return m_IsFind; } CPDF_TextPageFind findEngine(m_pTextPage.Get()); - bool ret = findEngine.FindFirst(m_findWhat, m_flags, - pdfium::Optional<FX_STRSIZE>(0)); + bool ret = + findEngine.FindFirst(m_findWhat, m_flags, pdfium::Optional<size_t>(0)); if (!ret) { m_IsFind = false; return m_IsFind; } - int order = -1, MatchedCount = 0; + int order = -1; + int MatchedCount = 0; while (ret) { ret = findEngine.FindNext(); if (ret) { int order1 = findEngine.GetCurOrder(); int MatchedCount1 = findEngine.GetMatchedCount(); - if (static_cast<FX_STRSIZE>((order1 + MatchedCount1)) > - m_findPreStart.value() + 1) + int temp = order1 + MatchedCount1; + if (temp < 0 || static_cast<size_t>(temp) > m_findPreStart.value() + 1) break; order = order1; MatchedCount = MatchedCount1; @@ -292,7 +291,7 @@ void CPDF_TextPageFind::ExtractFindWhat(const WideString& findwhat) { break; } } - FX_STRSIZE pos = 0; + size_t pos = 0; while (pos < csWord.GetLength()) { WideString curStr = csWord.Mid(pos, 1); wchar_t curChar = csWord[pos]; @@ -321,13 +320,13 @@ void CPDF_TextPageFind::ExtractFindWhat(const WideString& findwhat) { } bool CPDF_TextPageFind::IsMatchWholeWord(const WideString& csPageText, - FX_STRSIZE startPos, - FX_STRSIZE endPos) { + size_t startPos, + size_t endPos) { if (startPos > endPos) return false; wchar_t char_left = 0; wchar_t char_right = 0; - FX_STRSIZE char_count = endPos - startPos + 1; + size_t char_count = endPos - startPos + 1; if (char_count == 0) return false; if (char_count == 1 && csPageText[startPos] > 255) diff --git a/core/fpdftext/cpdf_textpagefind.h b/core/fpdftext/cpdf_textpagefind.h index face4e46b4..574f05ed0d 100644 --- a/core/fpdftext/cpdf_textpagefind.h +++ b/core/fpdftext/cpdf_textpagefind.h @@ -24,7 +24,7 @@ class CPDF_TextPageFind { bool FindFirst(const WideString& findwhat, int flags, - pdfium::Optional<FX_STRSIZE> startPos); + pdfium::Optional<size_t> startPos); bool FindNext(); bool FindPrev(); int GetCurOrder() const; @@ -33,8 +33,8 @@ class CPDF_TextPageFind { protected: void ExtractFindWhat(const WideString& findwhat); bool IsMatchWholeWord(const WideString& csPageText, - FX_STRSIZE startPos, - FX_STRSIZE endPos); + size_t startPos, + size_t endPos); bool ExtractSubString(WideString& rString, const wchar_t* lpszFullString, int iSubString, @@ -48,8 +48,8 @@ class CPDF_TextPageFind { WideString m_findWhat; int m_flags; std::vector<WideString> m_csFindWhatArray; - pdfium::Optional<FX_STRSIZE> m_findNextStart; - pdfium::Optional<FX_STRSIZE> m_findPreStart; + pdfium::Optional<size_t> m_findNextStart; + pdfium::Optional<size_t> m_findPreStart; bool m_bMatchCase; bool m_bMatchWholeWord; int m_resStart; diff --git a/core/fxcodec/codec/ccodec_jpegmodule.h b/core/fxcodec/codec/ccodec_jpegmodule.h index cc59924747..ca561317aa 100644 --- a/core/fxcodec/codec/ccodec_jpegmodule.h +++ b/core/fxcodec/codec/ccodec_jpegmodule.h @@ -60,7 +60,7 @@ class CCodec_JpegModule { #if _FX_OS_ == _FX_OS_WIN32_ || _FX_OS_ == _FX_OS_WIN64_ static bool JpegEncode(const RetainPtr<CFX_DIBSource>& pSource, uint8_t** dest_buf, - FX_STRSIZE* dest_size); + size_t* dest_size); #endif }; diff --git a/core/fxcodec/codec/ccodec_pngmodule.cpp b/core/fxcodec/codec/ccodec_pngmodule.cpp index a08e72f86d..d500745ca7 100644 --- a/core/fxcodec/codec/ccodec_pngmodule.cpp +++ b/core/fxcodec/codec/ccodec_pngmodule.cpp @@ -74,7 +74,7 @@ static void _png_load_bmp_attribute(png_structp png_ptr, #endif #if defined(PNG_TEXT_SUPPORTED) int i; - FX_STRSIZE len; + size_t len; const char* buf; int num_text; png_textp text = nullptr; @@ -86,8 +86,10 @@ static void _png_load_bmp_attribute(png_structp png_ptr, buf = "Author"; if (!memcmp(buf, text[i].key, std::min(len, FXSYS_strlen(buf)))) { pAttribute->m_strAuthor = - ByteString(reinterpret_cast<uint8_t*>(text[i].text), - static_cast<FX_STRSIZE>(text[i].text_length)); + text[i].text_length > 0 + ? ByteString(reinterpret_cast<uint8_t*>(text[i].text), + static_cast<size_t>(text[i].text_length)) + : ByteString(); } } } diff --git a/core/fxcodec/codec/ccodec_tiffmodule.cpp b/core/fxcodec/codec/ccodec_tiffmodule.cpp index 07d189200e..f11c480bd7 100644 --- a/core/fxcodec/codec/ccodec_tiffmodule.cpp +++ b/core/fxcodec/codec/ccodec_tiffmodule.cpp @@ -81,15 +81,15 @@ void* _TIFFrealloc(void* ptr, tmsize_t size) { } void _TIFFmemset(void* ptr, int val, tmsize_t size) { - memset(ptr, val, (size_t)size); + memset(ptr, val, static_cast<size_t>(size)); } void _TIFFmemcpy(void* des, const void* src, tmsize_t size) { - memcpy(des, src, (size_t)size); + memcpy(des, src, static_cast<size_t>(size)); } int _TIFFmemcmp(const void* ptr1, const void* ptr2, tmsize_t size) { - return memcmp(ptr1, ptr2, (size_t)size); + return memcmp(ptr1, ptr2, static_cast<size_t>(size)); } int _TIFFIfMultiplicationOverflow(tmsize_t op1, tmsize_t op2) { @@ -201,7 +201,7 @@ void Tiff_Exif_GetStringInfo(TIFF* tif_ctx, TIFFGetField(tif_ctx, tag, &buf); if (!buf) return; - FX_STRSIZE size = FXSYS_strlen(buf); + size_t size = FXSYS_strlen(buf); uint8_t* ptr = FX_Alloc(uint8_t, size + 1); memcpy(ptr, buf, size); ptr[size] = 0; diff --git a/core/fxcodec/codec/fx_codec_jpeg.cpp b/core/fxcodec/codec/fx_codec_jpeg.cpp index b77fc87394..b1dffbb210 100644 --- a/core/fxcodec/codec/fx_codec_jpeg.cpp +++ b/core/fxcodec/codec/fx_codec_jpeg.cpp @@ -369,7 +369,7 @@ static void _error_fatal1(j_common_ptr cinfo) { } static void _src_skip_data1(struct jpeg_decompress_struct* cinfo, long num) { - if (cinfo->src->bytes_in_buffer < (size_t)num) { + if (cinfo->src->bytes_in_buffer < static_cast<size_t>(num)) { auto* pContext = reinterpret_cast<CJpegContext*>(cinfo->client_data); pContext->m_SkipSize = (unsigned int)(num - cinfo->src->bytes_in_buffer); cinfo->src->bytes_in_buffer = 0; @@ -510,7 +510,7 @@ uint32_t CCodec_JpegModule::GetAvailInput(Context* pContext, #define JPEG_BLOCK_SIZE 1048576 bool CCodec_JpegModule::JpegEncode(const RetainPtr<CFX_DIBSource>& pSource, uint8_t** dest_buf, - FX_STRSIZE* dest_size) { + size_t* dest_size) { struct jpeg_error_mgr jerr; jerr.error_exit = _error_do_nothing; jerr.emit_message = _error_do_nothing1; @@ -603,7 +603,7 @@ bool CCodec_JpegModule::JpegEncode(const RetainPtr<CFX_DIBSource>& pSource, jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); FX_Free(line_buf); - *dest_size = dest_buf_length - (FX_STRSIZE)dest.free_in_buffer; + *dest_size = dest_buf_length - static_cast<size_t>(dest.free_in_buffer); return true; } diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp index aa1fb57775..bd195dda1d 100644 --- a/core/fxcrt/bytestring.cpp +++ b/core/fxcrt/bytestring.cpp @@ -91,12 +91,12 @@ namespace fxcrt { static_assert(sizeof(ByteString) <= sizeof(char*), "Strings must not require more space than pointers"); -ByteString::ByteString(const char* pStr, FX_STRSIZE nLen) { +ByteString::ByteString(const char* pStr, size_t nLen) { if (nLen) m_pData.Reset(StringData::Create(pStr, nLen)); } -ByteString::ByteString(const uint8_t* pStr, FX_STRSIZE nLen) { +ByteString::ByteString(const uint8_t* pStr, size_t nLen) { if (nLen) m_pData.Reset( StringData::Create(reinterpret_cast<const char*>(pStr), nLen)); @@ -128,7 +128,7 @@ ByteString::ByteString(const ByteStringView& str1, const ByteStringView& str2) { FX_SAFE_STRSIZE nSafeLen = str1.GetLength(); nSafeLen += str2.GetLength(); - FX_STRSIZE nNewLen = nSafeLen.ValueOrDie(); + size_t nNewLen = nSafeLen.ValueOrDie(); if (nNewLen == 0) return; @@ -143,13 +143,13 @@ ByteString::ByteString(const std::initializer_list<ByteStringView>& list) { for (const auto& item : list) nSafeLen += item.GetLength(); - FX_STRSIZE nNewLen = nSafeLen.ValueOrDie(); + size_t nNewLen = nSafeLen.ValueOrDie(); if (nNewLen == 0) return; m_pData.Reset(StringData::Create(nNewLen)); - FX_STRSIZE nOffset = 0; + size_t nOffset = 0; for (const auto& item : list) { m_pData->CopyContentsAt(nOffset, item.unterminated_c_str(), item.GetLength()); @@ -264,13 +264,13 @@ bool ByteString::EqualNoCase(const ByteStringView& str) const { if (!m_pData) return str.IsEmpty(); - FX_STRSIZE len = str.GetLength(); + size_t len = str.GetLength(); if (m_pData->m_nDataLength != len) return false; const uint8_t* pThis = (const uint8_t*)m_pData->m_String; const uint8_t* pThat = str.raw_str(); - for (FX_STRSIZE i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { if ((*pThis) != (*pThat)) { uint8_t bThis = FXSYS_tolower(*pThis); uint8_t bThat = FXSYS_tolower(*pThat); @@ -283,13 +283,13 @@ bool ByteString::EqualNoCase(const ByteStringView& str) const { return true; } -void ByteString::AssignCopy(const char* pSrcData, FX_STRSIZE nSrcLen) { +void ByteString::AssignCopy(const char* pSrcData, size_t nSrcLen) { AllocBeforeWrite(nSrcLen); m_pData->CopyContents(pSrcData, nSrcLen); m_pData->m_nDataLength = nSrcLen; } -void ByteString::ReallocBeforeWrite(FX_STRSIZE nNewLength) { +void ByteString::ReallocBeforeWrite(size_t nNewLength) { if (m_pData && m_pData->CanOperateInPlace(nNewLength)) return; @@ -300,7 +300,7 @@ void ByteString::ReallocBeforeWrite(FX_STRSIZE nNewLength) { RetainPtr<StringData> pNewData(StringData::Create(nNewLength)); if (m_pData) { - FX_STRSIZE nCopyLength = std::min(m_pData->m_nDataLength, nNewLength); + size_t nCopyLength = std::min(m_pData->m_nDataLength, nNewLength); pNewData->CopyContents(m_pData->m_String, nCopyLength); pNewData->m_nDataLength = nCopyLength; } else { @@ -310,7 +310,7 @@ void ByteString::ReallocBeforeWrite(FX_STRSIZE nNewLength) { m_pData.Swap(pNewData); } -void ByteString::AllocBeforeWrite(FX_STRSIZE nNewLength) { +void ByteString::AllocBeforeWrite(size_t nNewLength) { if (m_pData && m_pData->CanOperateInPlace(nNewLength)) return; @@ -322,7 +322,7 @@ void ByteString::AllocBeforeWrite(FX_STRSIZE nNewLength) { m_pData.Reset(StringData::Create(nNewLength)); } -void ByteString::ReleaseBuffer(FX_STRSIZE nNewLength) { +void ByteString::ReleaseBuffer(size_t nNewLength) { if (!m_pData) return; @@ -343,11 +343,11 @@ void ByteString::ReleaseBuffer(FX_STRSIZE nNewLength) { } } -void ByteString::Reserve(FX_STRSIZE len) { +void ByteString::Reserve(size_t len) { GetBuffer(len); } -char* ByteString::GetBuffer(FX_STRSIZE nMinBufLength) { +char* ByteString::GetBuffer(size_t nMinBufLength) { if (!m_pData) { if (nMinBufLength == 0) return nullptr; @@ -372,28 +372,28 @@ char* ByteString::GetBuffer(FX_STRSIZE nMinBufLength) { return m_pData->m_String; } -FX_STRSIZE ByteString::Delete(FX_STRSIZE index, FX_STRSIZE count) { +size_t ByteString::Delete(size_t index, size_t count) { if (!m_pData) return 0; - FX_STRSIZE old_length = m_pData->m_nDataLength; + size_t old_length = m_pData->m_nDataLength; if (count == 0 || - index != pdfium::clamp(index, static_cast<FX_STRSIZE>(0), old_length)) + index != pdfium::clamp(index, static_cast<size_t>(0), old_length)) return old_length; - FX_STRSIZE removal_length = index + count; + size_t removal_length = index + count; if (removal_length > old_length) return old_length; ReallocBeforeWrite(old_length); - FX_STRSIZE chars_to_copy = old_length - removal_length + 1; + size_t chars_to_copy = old_length - removal_length + 1; memmove(m_pData->m_String + index, m_pData->m_String + removal_length, chars_to_copy); m_pData->m_nDataLength = old_length - count; return m_pData->m_nDataLength; } -void ByteString::Concat(const char* pSrcData, FX_STRSIZE nSrcLen) { +void ByteString::Concat(const char* pSrcData, size_t nSrcLen) { if (!pSrcData || nSrcLen == 0) return; @@ -415,7 +415,7 @@ void ByteString::Concat(const char* pSrcData, FX_STRSIZE nSrcLen) { m_pData.Swap(pNewData); } -ByteString ByteString::Mid(FX_STRSIZE first, FX_STRSIZE count) const { +ByteString ByteString::Mid(size_t first, size_t count) const { if (!m_pData) return ByteString(); @@ -436,21 +436,21 @@ ByteString ByteString::Mid(FX_STRSIZE first, FX_STRSIZE count) const { return dest; } -ByteString ByteString::Left(FX_STRSIZE count) const { +ByteString ByteString::Left(size_t count) const { if (count == 0 || !IsValidLength(count)) return ByteString(); return Mid(0, count); } -ByteString ByteString::Right(FX_STRSIZE count) const { +ByteString ByteString::Right(size_t count) const { if (count == 0 || !IsValidLength(count)) return ByteString(); return Mid(GetLength() - count, count); } void ByteString::AllocCopy(ByteString& dest, - FX_STRSIZE nCopyLen, - FX_STRSIZE nCopyIndex) const { + size_t nCopyLen, + size_t nCopyIndex) const { if (nCopyLen == 0) return; @@ -472,7 +472,7 @@ ByteString ByteString::FormatInteger(int i) { void ByteString::FormatV(const char* pFormat, va_list argList) { va_list argListCopy; va_copy(argListCopy, argList); - FX_STRSIZE nMaxLen = vsnprintf(nullptr, 0, pFormat, argListCopy); + int nMaxLen = vsnprintf(nullptr, 0, pFormat, argListCopy); va_end(argListCopy); if (nMaxLen > 0) { GetBuffer(nMaxLen); @@ -495,18 +495,18 @@ void ByteString::Format(const char* pFormat, ...) { va_end(argList); } -void ByteString::SetAt(FX_STRSIZE index, char c) { +void ByteString::SetAt(size_t index, char c) { ASSERT(IsValidIndex(index)); ReallocBeforeWrite(m_pData->m_nDataLength); m_pData->m_String[index] = c; } -FX_STRSIZE ByteString::Insert(FX_STRSIZE location, char ch) { - const FX_STRSIZE cur_length = m_pData ? m_pData->m_nDataLength : 0; +size_t ByteString::Insert(size_t location, char ch) { + const size_t cur_length = m_pData ? m_pData->m_nDataLength : 0; if (!IsValidLength(location)) return cur_length; - const FX_STRSIZE new_length = cur_length + 1; + const size_t new_length = cur_length + 1; ReallocBeforeWrite(new_length); memmove(m_pData->m_String + location + 1, m_pData->m_String + location, new_length - location); @@ -515,46 +515,46 @@ FX_STRSIZE ByteString::Insert(FX_STRSIZE location, char ch) { return new_length; } -pdfium::Optional<FX_STRSIZE> ByteString::Find(char ch, FX_STRSIZE start) const { +pdfium::Optional<size_t> ByteString::Find(char ch, size_t start) const { if (!m_pData) - return pdfium::Optional<FX_STRSIZE>(); + return pdfium::Optional<size_t>(); if (!IsValidIndex(start)) - return pdfium::Optional<FX_STRSIZE>(); + return pdfium::Optional<size_t>(); const char* pStr = static_cast<const char*>( memchr(m_pData->m_String + start, ch, m_pData->m_nDataLength - start)); - return pStr ? pdfium::Optional<FX_STRSIZE>( - static_cast<FX_STRSIZE>(pStr - m_pData->m_String)) - : pdfium::Optional<FX_STRSIZE>(); + return pStr ? pdfium::Optional<size_t>( + static_cast<size_t>(pStr - m_pData->m_String)) + : pdfium::Optional<size_t>(); } -pdfium::Optional<FX_STRSIZE> ByteString::Find(const ByteStringView& subStr, - FX_STRSIZE start) const { +pdfium::Optional<size_t> ByteString::Find(const ByteStringView& subStr, + size_t start) const { if (!m_pData) - return pdfium::Optional<FX_STRSIZE>(); + return pdfium::Optional<size_t>(); if (!IsValidIndex(start)) - return pdfium::Optional<FX_STRSIZE>(); + return pdfium::Optional<size_t>(); const char* pStr = FX_strstr(m_pData->m_String + start, m_pData->m_nDataLength - start, subStr.unterminated_c_str(), subStr.GetLength()); - return pStr ? pdfium::Optional<FX_STRSIZE>( - static_cast<FX_STRSIZE>(pStr - m_pData->m_String)) - : pdfium::Optional<FX_STRSIZE>(); + return pStr ? pdfium::Optional<size_t>( + static_cast<size_t>(pStr - m_pData->m_String)) + : pdfium::Optional<size_t>(); } -pdfium::Optional<FX_STRSIZE> ByteString::ReverseFind(char ch) const { +pdfium::Optional<size_t> ByteString::ReverseFind(char ch) const { if (!m_pData) - return pdfium::Optional<FX_STRSIZE>(); + return pdfium::Optional<size_t>(); - FX_STRSIZE nLength = m_pData->m_nDataLength; + size_t nLength = m_pData->m_nDataLength; while (nLength--) { if (m_pData->m_String[nLength] == ch) - return pdfium::Optional<FX_STRSIZE>(nLength); + return pdfium::Optional<size_t>(nLength); } - return pdfium::Optional<FX_STRSIZE>(); + return pdfium::Optional<size_t>(); } void ByteString::MakeLower() { @@ -573,7 +573,7 @@ void ByteString::MakeUpper() { FXSYS_strupr(m_pData->m_String); } -FX_STRSIZE ByteString::Remove(char chRemove) { +size_t ByteString::Remove(char chRemove) { if (!m_pData || m_pData->m_nDataLength < 1) return 0; @@ -602,19 +602,19 @@ FX_STRSIZE ByteString::Remove(char chRemove) { } *pstrDest = 0; - FX_STRSIZE nCount = static_cast<FX_STRSIZE>(pstrSource - pstrDest); + size_t nCount = static_cast<size_t>(pstrSource - pstrDest); m_pData->m_nDataLength -= nCount; return nCount; } -FX_STRSIZE ByteString::Replace(const ByteStringView& pOld, - const ByteStringView& pNew) { +size_t ByteString::Replace(const ByteStringView& pOld, + const ByteStringView& pNew) { if (!m_pData || pOld.IsEmpty()) return 0; - FX_STRSIZE nSourceLen = pOld.GetLength(); - FX_STRSIZE nReplacementLen = pNew.GetLength(); - FX_STRSIZE nCount = 0; + size_t nSourceLen = pOld.GetLength(); + size_t nReplacementLen = pNew.GetLength(); + size_t nCount = 0; const char* pStart = m_pData->m_String; char* pEnd = m_pData->m_String + m_pData->m_nDataLength; while (1) { @@ -629,7 +629,7 @@ FX_STRSIZE ByteString::Replace(const ByteStringView& pOld, if (nCount == 0) return 0; - FX_STRSIZE nNewLength = + size_t nNewLength = m_pData->m_nDataLength + (nReplacementLen - nSourceLen) * nCount; if (nNewLength == 0) { @@ -640,7 +640,7 @@ FX_STRSIZE ByteString::Replace(const ByteStringView& pOld, RetainPtr<StringData> pNewData(StringData::Create(nNewLength)); pStart = m_pData->m_String; char* pDest = pNewData->m_String; - for (FX_STRSIZE i = 0; i < nCount; i++) { + for (size_t i = 0; i < nCount; i++) { const char* pTarget = FX_strstr(pStart, static_cast<int>(pEnd - pStart), pOld.unterminated_c_str(), nSourceLen); memcpy(pDest, pStart, pTarget - pStart); @@ -656,7 +656,7 @@ FX_STRSIZE ByteString::Replace(const ByteStringView& pOld, WideString ByteString::UTF8Decode() const { CFX_UTF8Decoder decoder; - for (FX_STRSIZE i = 0; i < GetLength(); i++) { + for (size_t i = 0; i < GetLength(); i++) { decoder.Input(static_cast<uint8_t>(m_pData->m_String[i])); } return WideString(decoder.GetResult()); @@ -671,10 +671,10 @@ int ByteString::Compare(const ByteStringView& str) const { if (!m_pData) { return str.IsEmpty() ? 0 : -1; } - FX_STRSIZE this_len = m_pData->m_nDataLength; - FX_STRSIZE that_len = str.GetLength(); - FX_STRSIZE min_len = std::min(this_len, that_len); - for (FX_STRSIZE i = 0; i < min_len; i++) { + size_t this_len = m_pData->m_nDataLength; + size_t that_len = str.GetLength(); + size_t min_len = std::min(this_len, that_len); + for (size_t i = 0; i < min_len; i++) { if (static_cast<uint8_t>(m_pData->m_String[i]) < str[i]) { return -1; } @@ -695,12 +695,12 @@ void ByteString::TrimRight(const ByteStringView& pTargets) { if (!m_pData || pTargets.IsEmpty()) return; - FX_STRSIZE pos = GetLength(); + size_t pos = GetLength(); if (pos == 0) return; while (pos) { - FX_STRSIZE i = 0; + size_t i = 0; while (i < pTargets.GetLength() && pTargets[i] != m_pData->m_String[pos - 1]) { i++; @@ -729,13 +729,13 @@ void ByteString::TrimLeft(const ByteStringView& pTargets) { if (!m_pData || pTargets.IsEmpty()) return; - FX_STRSIZE len = GetLength(); + size_t len = GetLength(); if (len == 0) return; - FX_STRSIZE pos = 0; + size_t pos = 0; while (pos < len) { - FX_STRSIZE i = 0; + size_t i = 0; while (i < pTargets.GetLength() && pTargets[i] != m_pData->m_String[pos]) { i++; } @@ -746,7 +746,7 @@ void ByteString::TrimLeft(const ByteStringView& pTargets) { } if (pos) { ReallocBeforeWrite(len); - FX_STRSIZE nDataLength = len - pos; + size_t nDataLength = len - pos; memmove(m_pData->m_String, m_pData->m_String + pos, (nDataLength + 1) * sizeof(char)); m_pData->m_nDataLength = nDataLength; @@ -763,8 +763,7 @@ void ByteString::TrimLeft() { ByteString ByteString::FormatFloat(float d, int precision) { char buf[32]; - FX_STRSIZE len = FX_ftoa(d, buf); - return ByteString(buf, len); + return ByteString(buf, FX_ftoa(d, buf)); } std::ostream& operator<<(std::ostream& os, const ByteString& str) { diff --git a/core/fxcrt/bytestring.h b/core/fxcrt/bytestring.h index eba9744402..2b01bc19aa 100644 --- a/core/fxcrt/bytestring.h +++ b/core/fxcrt/bytestring.h @@ -46,8 +46,8 @@ class ByteString { // NOLINTNEXTLINE(runtime/explicit) ByteString(wchar_t) = delete; - ByteString(const char* ptr, FX_STRSIZE len); - ByteString(const uint8_t* ptr, FX_STRSIZE len); + ByteString(const char* ptr, size_t len); + ByteString(const uint8_t* ptr, size_t len); explicit ByteString(const ByteStringView& bstrc); ByteString(const ByteStringView& bstrc1, const ByteStringView& bstrc2); @@ -91,13 +91,13 @@ class ByteString { return const_reverse_iterator(begin()); } - FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } - FX_STRSIZE GetStringLength() const { + size_t GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } + size_t GetStringLength() const { return m_pData ? FXSYS_strlen(m_pData->m_String) : 0; } bool IsEmpty() const { return !GetLength(); } - bool IsValidIndex(FX_STRSIZE index) const { return index < GetLength(); } - bool IsValidLength(FX_STRSIZE length) const { return length <= GetLength(); } + bool IsValidIndex(size_t index) const { return index < GetLength(); } + bool IsValidLength(size_t length) const { return length <= GetLength(); } int Compare(const ByteStringView& str) const; bool EqualNoCase(const ByteStringView& str) const; @@ -121,7 +121,7 @@ class ByteString { const ByteString& operator+=(const ByteString& str); const ByteString& operator+=(const ByteStringView& bstrc); - CharType operator[](const FX_STRSIZE index) const { + CharType operator[](const size_t index) const { ASSERT(IsValidIndex(index)); return m_pData ? m_pData->m_String[index] : 0; } @@ -129,34 +129,34 @@ class ByteString { CharType First() const { return GetLength() ? (*this)[0] : 0; } CharType Last() const { return GetLength() ? (*this)[GetLength() - 1] : 0; } - void SetAt(FX_STRSIZE index, char c); + void SetAt(size_t index, char c); - FX_STRSIZE Insert(FX_STRSIZE index, char ch); - FX_STRSIZE InsertAtFront(char ch) { return Insert(0, ch); } - FX_STRSIZE InsertAtBack(char ch) { return Insert(GetLength(), ch); } - FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1); + size_t Insert(size_t index, char ch); + size_t InsertAtFront(char ch) { return Insert(0, ch); } + size_t InsertAtBack(char ch) { return Insert(GetLength(), ch); } + size_t Delete(size_t index, size_t count = 1); void Format(const char* lpszFormat, ...); void FormatV(const char* lpszFormat, va_list argList); - void Reserve(FX_STRSIZE len); - char* GetBuffer(FX_STRSIZE len); - void ReleaseBuffer(FX_STRSIZE len); + void Reserve(size_t len); + char* GetBuffer(size_t len); + void ReleaseBuffer(size_t len); - ByteString Mid(FX_STRSIZE first, FX_STRSIZE count) const; - ByteString Left(FX_STRSIZE count) const; - ByteString Right(FX_STRSIZE count) const; + ByteString Mid(size_t first, size_t count) const; + ByteString Left(size_t count) const; + ByteString Right(size_t count) const; - pdfium::Optional<FX_STRSIZE> Find(const ByteStringView& lpszSub, - FX_STRSIZE start = 0) const; - pdfium::Optional<FX_STRSIZE> Find(char ch, FX_STRSIZE start = 0) const; - pdfium::Optional<FX_STRSIZE> ReverseFind(char ch) const; + pdfium::Optional<size_t> Find(const ByteStringView& lpszSub, + size_t start = 0) const; + pdfium::Optional<size_t> Find(char ch, size_t start = 0) const; + pdfium::Optional<size_t> ReverseFind(char ch) const; - bool Contains(const ByteStringView& lpszSub, FX_STRSIZE start = 0) const { + bool Contains(const ByteStringView& lpszSub, size_t start = 0) const { return Find(lpszSub, start).has_value(); } - bool Contains(char ch, FX_STRSIZE start = 0) const { + bool Contains(char ch, size_t start = 0) const { return Find(ch, start).has_value(); } @@ -171,10 +171,9 @@ class ByteString { void TrimLeft(char chTarget); void TrimLeft(const ByteStringView& lpszTargets); - FX_STRSIZE Replace(const ByteStringView& lpszOld, - const ByteStringView& lpszNew); + size_t Replace(const ByteStringView& lpszOld, const ByteStringView& lpszNew); - FX_STRSIZE Remove(char ch); + size_t Remove(char ch); WideString UTF8Decode() const; @@ -186,13 +185,11 @@ class ByteString { protected: using StringData = StringDataTemplate<char>; - void ReallocBeforeWrite(FX_STRSIZE nNewLen); - void AllocBeforeWrite(FX_STRSIZE nNewLen); - void AllocCopy(ByteString& dest, - FX_STRSIZE nCopyLen, - FX_STRSIZE nCopyIndex) const; - void AssignCopy(const char* pSrcData, FX_STRSIZE nSrcLen); - void Concat(const char* lpszSrcData, FX_STRSIZE nSrcLen); + void ReallocBeforeWrite(size_t nNewLen); + void AllocBeforeWrite(size_t nNewLen); + void AllocCopy(ByteString& dest, size_t nCopyLen, size_t nCopyIndex) const; + void AssignCopy(const char* pSrcData, size_t nSrcLen); + void Concat(const char* lpszSrcData, size_t nSrcLen); RetainPtr<StringData> m_pData; diff --git a/core/fxcrt/bytestring_unittest.cpp b/core/fxcrt/bytestring_unittest.cpp index e1c832e114..d3597ad421 100644 --- a/core/fxcrt/bytestring_unittest.cpp +++ b/core/fxcrt/bytestring_unittest.cpp @@ -550,7 +550,7 @@ TEST(ByteString, Find) { EXPECT_FALSE(empty_string.Find('a').has_value()); EXPECT_FALSE(empty_string.Find('\0').has_value()); - pdfium::Optional<FX_STRSIZE> result; + pdfium::Optional<size_t> result; ByteString single_string("a"); result = single_string.Find('a'); ASSERT_TRUE(result.has_value()); @@ -599,7 +599,7 @@ TEST(ByteString, ReverseFind) { EXPECT_FALSE(empty_string.ReverseFind('a').has_value()); EXPECT_FALSE(empty_string.ReverseFind('\0').has_value()); - pdfium::Optional<FX_STRSIZE> result; + pdfium::Optional<size_t> result; ByteString single_string("a"); result = single_string.ReverseFind('a'); ASSERT_TRUE(result.has_value()); @@ -978,7 +978,7 @@ TEST(ByteStringView, FromVector) { std::vector<uint8_t> lower_a_vec(10, static_cast<uint8_t>('a')); ByteStringView lower_a_string(lower_a_vec); - EXPECT_EQ(static_cast<FX_STRSIZE>(10), lower_a_string.GetLength()); + EXPECT_EQ(static_cast<size_t>(10), lower_a_string.GetLength()); EXPECT_EQ("aaaaaaaaaa", lower_a_string); std::vector<uint8_t> cleared_vec; @@ -1012,7 +1012,7 @@ TEST(ByteStringView, Find) { EXPECT_FALSE(empty_string.Find('a').has_value()); EXPECT_FALSE(empty_string.Find('\0').has_value()); - pdfium::Optional<FX_STRSIZE> result; + pdfium::Optional<size_t> result; ByteStringView single_string("a"); result = single_string.Find('a'); ASSERT_TRUE(result.has_value()); diff --git a/core/fxcrt/cfx_binarybuf.cpp b/core/fxcrt/cfx_binarybuf.cpp index b826fdd5b5..d1bd05385d 100644 --- a/core/fxcrt/cfx_binarybuf.cpp +++ b/core/fxcrt/cfx_binarybuf.cpp @@ -12,14 +12,14 @@ CFX_BinaryBuf::CFX_BinaryBuf() : m_AllocStep(0), m_AllocSize(0), m_DataSize(0) {} -CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size) +CFX_BinaryBuf::CFX_BinaryBuf(size_t size) : m_AllocStep(0), m_AllocSize(size), m_DataSize(size) { m_pBuffer.reset(FX_Alloc(uint8_t, size)); } CFX_BinaryBuf::~CFX_BinaryBuf() {} -void CFX_BinaryBuf::Delete(FX_STRSIZE start_index, FX_STRSIZE count) { +void CFX_BinaryBuf::Delete(size_t start_index, size_t count) { if (!m_pBuffer || count > m_DataSize || start_index > m_DataSize - count) return; @@ -28,7 +28,7 @@ void CFX_BinaryBuf::Delete(FX_STRSIZE start_index, FX_STRSIZE count) { m_DataSize -= count; } -FX_STRSIZE CFX_BinaryBuf::GetLength() const { +size_t CFX_BinaryBuf::GetLength() const { return m_DataSize; } @@ -42,20 +42,20 @@ std::unique_ptr<uint8_t, FxFreeDeleter> CFX_BinaryBuf::DetachBuffer() { return std::move(m_pBuffer); } -void CFX_BinaryBuf::EstimateSize(FX_STRSIZE size, FX_STRSIZE step) { +void CFX_BinaryBuf::EstimateSize(size_t size, size_t step) { m_AllocStep = step; if (m_AllocSize < size) ExpandBuf(size - m_DataSize); } -void CFX_BinaryBuf::ExpandBuf(FX_STRSIZE add_size) { +void CFX_BinaryBuf::ExpandBuf(size_t add_size) { FX_SAFE_STRSIZE new_size = m_DataSize; new_size += add_size; if (m_AllocSize >= new_size.ValueOrDie()) return; - FX_STRSIZE alloc_step = std::max(static_cast<FX_STRSIZE>(128), - m_AllocStep ? m_AllocStep : m_AllocSize / 4); + size_t alloc_step = std::max(static_cast<size_t>(128), + m_AllocStep ? m_AllocStep : m_AllocSize / 4); new_size += alloc_step - 1; // Quantize, don't combine these lines. new_size /= alloc_step; new_size *= alloc_step; @@ -65,8 +65,8 @@ void CFX_BinaryBuf::ExpandBuf(FX_STRSIZE add_size) { : FX_Alloc(uint8_t, m_AllocSize)); } -void CFX_BinaryBuf::AppendBlock(const void* pBuf, FX_STRSIZE size) { - if (size <= 0) +void CFX_BinaryBuf::AppendBlock(const void* pBuf, size_t size) { + if (size == 0) return; ExpandBuf(size); @@ -78,9 +78,7 @@ void CFX_BinaryBuf::AppendBlock(const void* pBuf, FX_STRSIZE size) { m_DataSize += size; } -void CFX_BinaryBuf::InsertBlock(FX_STRSIZE pos, - const void* pBuf, - FX_STRSIZE size) { +void CFX_BinaryBuf::InsertBlock(size_t pos, const void* pBuf, size_t size) { if (size <= 0) return; diff --git a/core/fxcrt/cfx_binarybuf.h b/core/fxcrt/cfx_binarybuf.h index 186d8d1b88..1a1c821bb9 100644 --- a/core/fxcrt/cfx_binarybuf.h +++ b/core/fxcrt/cfx_binarybuf.h @@ -16,17 +16,17 @@ class CFX_BinaryBuf { public: CFX_BinaryBuf(); - explicit CFX_BinaryBuf(FX_STRSIZE size); + explicit CFX_BinaryBuf(size_t size); virtual ~CFX_BinaryBuf(); uint8_t* GetBuffer() const { return m_pBuffer.get(); } - FX_STRSIZE GetSize() const { return m_DataSize; } - virtual FX_STRSIZE GetLength() const; + size_t GetSize() const { return m_DataSize; } + virtual size_t GetLength() const; bool IsEmpty() const { return GetLength() == 0; } void Clear(); - void EstimateSize(FX_STRSIZE size, FX_STRSIZE alloc_step = 0); - void AppendBlock(const void* pBuf, FX_STRSIZE size); + void EstimateSize(size_t size, size_t alloc_step = 0); + void AppendBlock(const void* pBuf, size_t size); void AppendString(const ByteString& str) { AppendBlock(str.c_str(), str.GetLength()); } @@ -36,18 +36,18 @@ class CFX_BinaryBuf { m_pBuffer.get()[m_DataSize++] = byte; } - void InsertBlock(FX_STRSIZE pos, const void* pBuf, FX_STRSIZE size); - void Delete(FX_STRSIZE start_index, FX_STRSIZE count); + void InsertBlock(size_t pos, const void* pBuf, size_t size); + void Delete(size_t start_index, size_t count); // Releases ownership of |m_pBuffer| and returns it. std::unique_ptr<uint8_t, FxFreeDeleter> DetachBuffer(); protected: - void ExpandBuf(FX_STRSIZE size); + void ExpandBuf(size_t size); - FX_STRSIZE m_AllocStep; - FX_STRSIZE m_AllocSize; - FX_STRSIZE m_DataSize; + size_t m_AllocStep; + size_t m_AllocSize; + size_t m_DataSize; std::unique_ptr<uint8_t, FxFreeDeleter> m_pBuffer; }; diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp index 3c0b5d5aef..f2590ecfd6 100644 --- a/core/fxcrt/cfx_seekablestreamproxy.cpp +++ b/core/fxcrt/cfx_seekablestreamproxy.cpp @@ -25,10 +25,10 @@ namespace { // Returns {src bytes consumed, dst bytes produced}. -std::pair<FX_STRSIZE, FX_STRSIZE> UTF8Decode(const char* pSrc, - FX_STRSIZE srcLen, - wchar_t* pDst, - FX_STRSIZE dstLen) { +std::pair<size_t, size_t> UTF8Decode(const char* pSrc, + size_t srcLen, + wchar_t* pDst, + size_t dstLen) { ASSERT(pDst && dstLen > 0); if (srcLen < 1) @@ -36,9 +36,9 @@ std::pair<FX_STRSIZE, FX_STRSIZE> UTF8Decode(const char* pSrc, uint32_t dwCode = 0; int32_t iPending = 0; - FX_STRSIZE iSrcNum = 0; - FX_STRSIZE iDstNum = 0; - FX_STRSIZE iIndex = 0; + size_t iSrcNum = 0; + size_t iDstNum = 0; + size_t iIndex = 0; int32_t k = 1; while (iIndex < srcLen) { uint8_t byte = static_cast<uint8_t>(*(pSrc + iIndex)); @@ -91,18 +91,18 @@ std::pair<FX_STRSIZE, FX_STRSIZE> UTF8Decode(const char* pSrc, return {iSrcNum, iDstNum}; } -void UTF16ToWChar(void* pBuffer, FX_STRSIZE iLength) { +void UTF16ToWChar(void* pBuffer, size_t iLength) { ASSERT(pBuffer); ASSERT(iLength > 0); ASSERT(sizeof(wchar_t) > 2); uint16_t* pSrc = static_cast<uint16_t*>(pBuffer); wchar_t* pDst = static_cast<wchar_t*>(pBuffer); - for (FX_STRSIZE i = 0; i < iLength; i++) + for (size_t i = 0; i < iLength; i++) pDst[i] = static_cast<wchar_t>(pSrc[i]); } -void SwapByteOrder(wchar_t* pStr, FX_STRSIZE iLength) { +void SwapByteOrder(wchar_t* pStr, size_t iLength) { ASSERT(pStr); uint16_t wch; @@ -174,7 +174,7 @@ CFX_SeekableStreamProxy::CFX_SeekableStreamProxy( Seek(From::Begin, static_cast<FX_FILESIZE>(m_wBOMLength)); } -CFX_SeekableStreamProxy::CFX_SeekableStreamProxy(uint8_t* data, FX_STRSIZE size) +CFX_SeekableStreamProxy::CFX_SeekableStreamProxy(uint8_t* data, size_t size) : CFX_SeekableStreamProxy( pdfium::MakeRetain<CFX_MemoryStream>(data, size, false), false) {} @@ -203,15 +203,14 @@ void CFX_SeekableStreamProxy::SetCodePage(uint16_t wCodePage) { m_wCodePage = wCodePage; } -FX_STRSIZE CFX_SeekableStreamProxy::ReadData(uint8_t* pBuffer, - FX_STRSIZE iBufferSize) { +size_t CFX_SeekableStreamProxy::ReadData(uint8_t* pBuffer, size_t iBufferSize) { ASSERT(pBuffer && iBufferSize > 0); if (m_IsWriteStream) return 0; iBufferSize = - std::min(iBufferSize, static_cast<FX_STRSIZE>(GetLength() - m_iPosition)); + std::min(iBufferSize, static_cast<size_t>(GetLength() - m_iPosition)); if (iBufferSize <= 0) return 0; @@ -224,9 +223,9 @@ FX_STRSIZE CFX_SeekableStreamProxy::ReadData(uint8_t* pBuffer, return new_pos.IsValid() ? iBufferSize : 0; } -FX_STRSIZE CFX_SeekableStreamProxy::ReadString(wchar_t* pStr, - FX_STRSIZE iMaxLength, - bool* bEOS) { +size_t CFX_SeekableStreamProxy::ReadString(wchar_t* pStr, + size_t iMaxLength, + bool* bEOS) { if (!pStr || iMaxLength == 0) return 0; @@ -235,8 +234,8 @@ FX_STRSIZE CFX_SeekableStreamProxy::ReadString(wchar_t* pStr, if (m_wCodePage == FX_CODEPAGE_UTF16LE || m_wCodePage == FX_CODEPAGE_UTF16BE) { - FX_STRSIZE iBytes = iMaxLength * 2; - FX_STRSIZE iLen = ReadData(reinterpret_cast<uint8_t*>(pStr), iBytes); + size_t iBytes = iMaxLength * 2; + size_t iLen = ReadData(reinterpret_cast<uint8_t*>(pStr), iBytes); iMaxLength = iLen / 2; if (sizeof(wchar_t) > 2 && iMaxLength > 0) UTF16ToWChar(pStr, iMaxLength); @@ -246,17 +245,17 @@ FX_STRSIZE CFX_SeekableStreamProxy::ReadString(wchar_t* pStr, } else { FX_FILESIZE pos = GetPosition(); - FX_STRSIZE iBytes = - std::min(iMaxLength, static_cast<FX_STRSIZE>(GetLength() - pos)); + size_t iBytes = + std::min(iMaxLength, static_cast<size_t>(GetLength() - pos)); if (iBytes > 0) { std::vector<uint8_t> buf(iBytes); - FX_STRSIZE iLen = ReadData(buf.data(), iBytes); + size_t iLen = ReadData(buf.data(), iBytes); if (m_wCodePage != FX_CODEPAGE_UTF8) return 0; - FX_STRSIZE iSrc = 0; + size_t iSrc = 0; std::tie(iSrc, iMaxLength) = UTF8Decode( reinterpret_cast<const char*>(buf.data()), iLen, pStr, iMaxLength); Seek(From::Current, iSrc - iLen); diff --git a/core/fxcrt/cfx_seekablestreamproxy.h b/core/fxcrt/cfx_seekablestreamproxy.h index cadc96816d..c25ab3c9b6 100644 --- a/core/fxcrt/cfx_seekablestreamproxy.h +++ b/core/fxcrt/cfx_seekablestreamproxy.h @@ -25,11 +25,11 @@ class CFX_SeekableStreamProxy : public Retainable { FX_FILESIZE GetLength() const { return m_pStream->GetSize(); } FX_FILESIZE GetPosition() { return m_iPosition; } - FX_STRSIZE GetBOMLength() const { return m_wBOMLength; } + size_t GetBOMLength() const { return m_wBOMLength; } bool IsEOF() const { return m_iPosition >= GetLength(); } void Seek(From eSeek, FX_FILESIZE iOffset); - FX_STRSIZE ReadString(wchar_t* pStr, FX_STRSIZE iMaxLength, bool* bEOS); + size_t ReadString(wchar_t* pStr, size_t iMaxLength, bool* bEOS); void WriteString(const WideStringView& str); @@ -39,14 +39,14 @@ class CFX_SeekableStreamProxy : public Retainable { private: CFX_SeekableStreamProxy(const RetainPtr<IFX_SeekableStream>& stream, bool isWriteSteam); - CFX_SeekableStreamProxy(uint8_t* data, FX_STRSIZE size); + CFX_SeekableStreamProxy(uint8_t* data, size_t size); ~CFX_SeekableStreamProxy() override; - FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize); + size_t ReadData(uint8_t* pBuffer, size_t iBufferSize); bool m_IsWriteStream; uint16_t m_wCodePage; - FX_STRSIZE m_wBOMLength; + size_t m_wBOMLength; FX_FILESIZE m_iPosition; RetainPtr<IFX_SeekableStream> m_pStream; }; diff --git a/core/fxcrt/cfx_widetextbuf.cpp b/core/fxcrt/cfx_widetextbuf.cpp index d51e5ea314..08e4921560 100644 --- a/core/fxcrt/cfx_widetextbuf.cpp +++ b/core/fxcrt/cfx_widetextbuf.cpp @@ -6,7 +6,7 @@ #include "core/fxcrt/cfx_widetextbuf.h" -FX_STRSIZE CFX_WideTextBuf::GetLength() const { +size_t CFX_WideTextBuf::GetLength() const { return m_DataSize / sizeof(wchar_t); } @@ -29,10 +29,10 @@ CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const WideString& str) { CFX_WideTextBuf& CFX_WideTextBuf::operator<<(int i) { char buf[32]; FXSYS_itoa(i, buf, 10); - FX_STRSIZE len = FXSYS_strlen(buf); + size_t len = FXSYS_strlen(buf); ExpandBuf(len * sizeof(wchar_t)); wchar_t* str = (wchar_t*)(m_pBuffer.get() + m_DataSize); - for (FX_STRSIZE j = 0; j < len; j++) { + for (size_t j = 0; j < len; j++) { *str++ = buf[j]; } m_DataSize += len * sizeof(wchar_t); @@ -41,10 +41,10 @@ CFX_WideTextBuf& CFX_WideTextBuf::operator<<(int i) { CFX_WideTextBuf& CFX_WideTextBuf::operator<<(double f) { char buf[32]; - FX_STRSIZE len = FX_ftoa((float)f, buf); + size_t len = FX_ftoa((float)f, buf); ExpandBuf(len * sizeof(wchar_t)); wchar_t* str = (wchar_t*)(m_pBuffer.get() + m_DataSize); - for (FX_STRSIZE i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { *str++ = buf[i]; } m_DataSize += len * sizeof(wchar_t); diff --git a/core/fxcrt/cfx_widetextbuf.h b/core/fxcrt/cfx_widetextbuf.h index 77fe4141f9..84553a3e59 100644 --- a/core/fxcrt/cfx_widetextbuf.h +++ b/core/fxcrt/cfx_widetextbuf.h @@ -14,7 +14,7 @@ class CFX_WideTextBuf : public CFX_BinaryBuf { public: void AppendChar(wchar_t wch); - FX_STRSIZE GetLength() const override; + size_t GetLength() const override; wchar_t* GetBuffer() const { return reinterpret_cast<wchar_t*>(m_pBuffer.get()); } diff --git a/core/fxcrt/fx_safe_types.h b/core/fxcrt/fx_safe_types.h index c7362b82f3..aae608096f 100644 --- a/core/fxcrt/fx_safe_types.h +++ b/core/fxcrt/fx_safe_types.h @@ -14,6 +14,6 @@ typedef pdfium::base::CheckedNumeric<uint32_t> FX_SAFE_UINT32; typedef pdfium::base::CheckedNumeric<int32_t> FX_SAFE_INT32; typedef pdfium::base::CheckedNumeric<size_t> FX_SAFE_SIZE_T; typedef pdfium::base::CheckedNumeric<FX_FILESIZE> FX_SAFE_FILESIZE; -typedef pdfium::base::CheckedNumeric<FX_STRSIZE> FX_SAFE_STRSIZE; +typedef pdfium::base::CheckedNumeric<size_t> FX_SAFE_STRSIZE; #endif // CORE_FXCRT_FX_SAFE_TYPES_H_ diff --git a/core/fxcrt/fx_string.cpp b/core/fxcrt/fx_string.cpp index ce4e187837..233c5e64b7 100644 --- a/core/fxcrt/fx_string.cpp +++ b/core/fxcrt/fx_string.cpp @@ -62,7 +62,7 @@ class CFX_UTF8Encoder { } // namespace ByteString FX_UTF8Encode(const WideStringView& wsStr) { - FX_STRSIZE len = wsStr.GetLength(); + size_t len = wsStr.GetLength(); const wchar_t* pStr = wsStr.unterminated_c_str(); CFX_UTF8Encoder encoder; while (len-- > 0) @@ -99,7 +99,7 @@ bool FX_atonum(const ByteStringView& strc, void* pData) { pdfium::base::CheckedNumeric<uint32_t> integer = 0; bool bNegative = false; bool bSigned = false; - FX_STRSIZE cc = 0; + size_t cc = 0; if (strc[0] == '+') { cc++; bSigned = true; @@ -184,7 +184,7 @@ float FX_atof(const WideStringView& wsStr) { return FX_atof(FX_UTF8Encode(wsStr).c_str()); } -FX_STRSIZE FX_ftoa(float d, char* buf) { +size_t FX_ftoa(float d, char* buf) { buf[0] = '0'; buf[1] = '\0'; if (d == 0.0f) { @@ -208,13 +208,13 @@ FX_STRSIZE FX_ftoa(float d, char* buf) { return 1; } char buf2[32]; - FX_STRSIZE buf_size = 0; + size_t buf_size = 0; if (bNegative) { buf[buf_size++] = '-'; } int i = scaled / scale; FXSYS_itoa(i, buf2, 10); - FX_STRSIZE len = FXSYS_strlen(buf2); + size_t len = FXSYS_strlen(buf2); memcpy(buf + buf_size, buf2, len); buf_size += len; int fraction = scaled % scale; diff --git a/core/fxcrt/fx_string.h b/core/fxcrt/fx_string.h index 0481a15d34..4c24181e37 100644 --- a/core/fxcrt/fx_string.h +++ b/core/fxcrt/fx_string.h @@ -18,6 +18,6 @@ ByteString FX_UTF8Encode(const WideStringView& wsStr); float FX_atof(const ByteStringView& str); float FX_atof(const WideStringView& wsStr); bool FX_atonum(const ByteStringView& str, void* pData); -FX_STRSIZE FX_ftoa(float f, char* buf); +size_t FX_ftoa(float f, char* buf); #endif // CORE_FXCRT_FX_STRING_H_ diff --git a/core/fxcrt/fx_system.h b/core/fxcrt/fx_system.h index 426dc085fc..2c84b02238 100644 --- a/core/fxcrt/fx_system.h +++ b/core/fxcrt/fx_system.h @@ -76,10 +76,6 @@ extern "C" { #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) -// Unsigned value used to represent a location or range in a string. -// TODO(rharrison): Remove and use size_t directly once int->size_t stabilizes. -typedef size_t FX_STRSIZE; - // PDFium file sizes match the platform, but PDFium itself does not support // files larger than 2GB even if the platform does. The value must be signed // to support -1 error returns. @@ -120,15 +116,15 @@ typedef size_t FX_STRSIZE; #include "third_party/base/numerics/safe_conversions.h" -#define FXSYS_strlen(ptr) pdfium::base::checked_cast<FX_STRSIZE>(strlen(ptr)) -#define FXSYS_wcslen(ptr) pdfium::base::checked_cast<FX_STRSIZE>(wcslen(ptr)) +#define FXSYS_strlen(ptr) (strlen(ptr)) +#define FXSYS_wcslen(ptr) (wcslen(ptr)) // Overloaded functions for C++ templates -inline FX_STRSIZE FXSYS_len(const char* ptr) { +inline size_t FXSYS_len(const char* ptr) { return FXSYS_strlen(ptr); } -inline FX_STRSIZE FXSYS_len(const wchar_t* ptr) { +inline size_t FXSYS_len(const wchar_t* ptr) { return FXSYS_wcslen(ptr); } @@ -150,8 +146,8 @@ inline const wchar_t* FXSYS_chr(const wchar_t* ptr, wchar_t ch, size_t len) { extern "C" { #else -#define FXSYS_strlen(ptr) ((FX_STRSIZE)strlen(ptr)) -#define FXSYS_wcslen(ptr) ((FX_STRSIZE)wcslen(ptr)) +#define FXSYS_strlen(ptr) (strlen(ptr)) +#define FXSYS_wcslen(ptr) (wcslen(ptr)) #endif // __cplusplus #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ diff --git a/core/fxcrt/string_data_template.h b/core/fxcrt/string_data_template.h index afec50fe01..bc797c07e2 100644 --- a/core/fxcrt/string_data_template.h +++ b/core/fxcrt/string_data_template.h @@ -16,13 +16,13 @@ namespace fxcrt { template <typename CharType> class StringDataTemplate { public: - static StringDataTemplate* Create(FX_STRSIZE nLen) { + static StringDataTemplate* Create(size_t nLen) { ASSERT(nLen > 0); // Calculate space needed for the fixed portion of the struct plus the // NUL char that is not included in |m_nAllocLength|. int overhead = offsetof(StringDataTemplate, m_String) + sizeof(CharType); - pdfium::base::CheckedNumeric<FX_STRSIZE> nSize = nLen; + pdfium::base::CheckedNumeric<size_t> nSize = nLen; nSize *= sizeof(CharType); nSize += overhead; @@ -32,8 +32,8 @@ class StringDataTemplate { // by using this otherwise wasted space. nSize += 7; nSize &= ~7; - FX_STRSIZE totalSize = nSize.ValueOrDie(); - FX_STRSIZE usableLen = (totalSize - overhead) / sizeof(CharType); + size_t totalSize = nSize.ValueOrDie(); + size_t usableLen = (totalSize - overhead) / sizeof(CharType); ASSERT(usableLen >= nLen); void* pData = pdfium::base::PartitionAllocGeneric( @@ -47,7 +47,7 @@ class StringDataTemplate { return result; } - static StringDataTemplate* Create(const CharType* pStr, FX_STRSIZE nLen) { + static StringDataTemplate* Create(const CharType* pStr, size_t nLen) { StringDataTemplate* result = Create(nLen); result->CopyContents(pStr, nLen); return result; @@ -60,7 +60,7 @@ class StringDataTemplate { this); } - bool CanOperateInPlace(FX_STRSIZE nTotalLen) const { + bool CanOperateInPlace(size_t nTotalLen) const { return m_nRefs <= 1 && nTotalLen <= m_nAllocLength; } @@ -70,15 +70,13 @@ class StringDataTemplate { (other.m_nDataLength + 1) * sizeof(CharType)); } - void CopyContents(const CharType* pStr, FX_STRSIZE nLen) { + void CopyContents(const CharType* pStr, size_t nLen) { ASSERT(nLen >= 0 && nLen <= m_nAllocLength); memcpy(m_String, pStr, nLen * sizeof(CharType)); m_String[nLen] = 0; } - void CopyContentsAt(FX_STRSIZE offset, - const CharType* pStr, - FX_STRSIZE nLen) { + void CopyContentsAt(size_t offset, const CharType* pStr, size_t nLen) { ASSERT(offset >= 0 && nLen >= 0 && offset + nLen <= m_nAllocLength); memcpy(m_String + offset, pStr, nLen * sizeof(CharType)); m_String[offset + nLen] = 0; @@ -91,19 +89,17 @@ class StringDataTemplate { // the address space itself is a good upper bound on it. intptr_t m_nRefs; - // |FX_STRSIZE| is currently typedef'd as |int|. - // TODO(palmer): It should be a |size_t|, or at least unsigned. // These lengths are in terms of number of characters, not bytes, and do not // include the terminating NUL character, but the underlying buffer is sized // to be capable of holding it. - FX_STRSIZE m_nDataLength; - FX_STRSIZE m_nAllocLength; + size_t m_nDataLength; + size_t m_nAllocLength; // Not really 1, variable size. CharType m_String[1]; private: - StringDataTemplate(FX_STRSIZE dataLen, FX_STRSIZE allocLen) + StringDataTemplate(size_t dataLen, size_t allocLen) : m_nRefs(0), m_nDataLength(dataLen), m_nAllocLength(allocLen) { ASSERT(dataLen >= 0); ASSERT(dataLen <= allocLen); diff --git a/core/fxcrt/string_view_template.h b/core/fxcrt/string_view_template.h index 31c2c1e2af..346e5a469d 100644 --- a/core/fxcrt/string_view_template.h +++ b/core/fxcrt/string_view_template.h @@ -39,13 +39,13 @@ class StringViewTemplate { : m_Ptr(reinterpret_cast<const UnsignedType*>(ptr)), m_Length(ptr ? FXSYS_len(ptr) : 0) {} - StringViewTemplate(const CharType* ptr, FX_STRSIZE len) + StringViewTemplate(const CharType* ptr, size_t len) : m_Ptr(reinterpret_cast<const UnsignedType*>(ptr)), m_Length(len) {} template <typename U = UnsignedType> StringViewTemplate( const UnsignedType* ptr, - FX_STRSIZE size, + size_t size, typename std::enable_if<!std::is_same<U, CharType>::value>::type* = 0) : m_Ptr(ptr), m_Length(size) {} @@ -64,7 +64,7 @@ class StringViewTemplate { // Any changes to |vec| invalidate the string. explicit StringViewTemplate(const std::vector<UnsignedType>& vec) { - m_Length = pdfium::CollectionSize<FX_STRSIZE>(vec); + m_Length = pdfium::CollectionSize<size_t>(vec); m_Ptr = m_Length ? vec.data() : nullptr; } @@ -116,8 +116,8 @@ class StringViewTemplate { return 0; uint32_t strid = 0; - FX_STRSIZE size = std::min(static_cast<FX_STRSIZE>(4), m_Length); - for (FX_STRSIZE i = 0; i < size; i++) + size_t size = std::min(static_cast<size_t>(4), m_Length); + for (size_t i = 0; i < size; i++) strid = strid * 256 + m_Ptr.Get()[i]; return strid << ((4 - size) * 8); @@ -128,12 +128,12 @@ class StringViewTemplate { return reinterpret_cast<const CharType*>(m_Ptr.Get()); } - FX_STRSIZE GetLength() const { return m_Length; } + size_t GetLength() const { return m_Length; } bool IsEmpty() const { return m_Length == 0; } - bool IsValidIndex(FX_STRSIZE index) const { return index < GetLength(); } - bool IsValidLength(FX_STRSIZE length) const { return length <= GetLength(); } + bool IsValidIndex(size_t index) const { return index < GetLength(); } + bool IsValidLength(size_t length) const { return length <= GetLength(); } - const UnsignedType& operator[](const FX_STRSIZE index) const { + const UnsignedType& operator[](const size_t index) const { ASSERT(IsValidIndex(index)); return m_Ptr.Get()[index]; } @@ -144,22 +144,22 @@ class StringViewTemplate { return GetLength() ? (*this)[GetLength() - 1] : 0; } - const CharType CharAt(const FX_STRSIZE index) const { + const CharType CharAt(const size_t index) const { ASSERT(IsValidIndex(index)); return static_cast<CharType>(m_Ptr.Get()[index]); } - pdfium::Optional<FX_STRSIZE> Find(CharType ch) const { + pdfium::Optional<size_t> Find(CharType ch) const { const UnsignedType* found = reinterpret_cast<const UnsignedType*>(FXSYS_chr( reinterpret_cast<const CharType*>(m_Ptr.Get()), ch, m_Length)); - return found ? pdfium::Optional<FX_STRSIZE>(found - m_Ptr.Get()) - : pdfium::Optional<FX_STRSIZE>(); + return found ? pdfium::Optional<size_t>(found - m_Ptr.Get()) + : pdfium::Optional<size_t>(); } bool Contains(CharType ch) const { return Find(ch).has_value(); } - StringViewTemplate Mid(FX_STRSIZE first, FX_STRSIZE count) const { + StringViewTemplate Mid(size_t first, size_t count) const { if (!m_Ptr.Get()) return StringViewTemplate(); @@ -175,13 +175,13 @@ class StringViewTemplate { return StringViewTemplate(m_Ptr.Get() + first, count); } - StringViewTemplate Left(FX_STRSIZE count) const { + StringViewTemplate Left(size_t count) const { if (count == 0 || !IsValidLength(count)) return StringViewTemplate(); return Mid(0, count); } - StringViewTemplate Right(FX_STRSIZE count) const { + StringViewTemplate Right(size_t count) const { if (count == 0 || !IsValidLength(count)) return StringViewTemplate(); return Mid(GetLength() - count, count); @@ -191,7 +191,7 @@ class StringViewTemplate { if (IsEmpty()) return StringViewTemplate(); - FX_STRSIZE pos = GetLength(); + size_t pos = GetLength(); while (pos && CharAt(pos - 1) == ch) pos--; @@ -217,7 +217,7 @@ class StringViewTemplate { protected: UnownedPtr<const UnsignedType> m_Ptr; - FX_STRSIZE m_Length; + size_t m_Length; private: void* operator new(size_t) throw() { return nullptr; } diff --git a/core/fxcrt/widestring.cpp b/core/fxcrt/widestring.cpp index 5fe7ee4777..a4632ee9db 100644 --- a/core/fxcrt/widestring.cpp +++ b/core/fxcrt/widestring.cpp @@ -55,9 +55,9 @@ const wchar_t* FX_wcsstr(const wchar_t* haystack, return nullptr; } -pdfium::Optional<FX_STRSIZE> GuessSizeForVSWPrintf(const wchar_t* pFormat, - va_list argList) { - FX_STRSIZE nMaxLen = 0; +pdfium::Optional<size_t> GuessSizeForVSWPrintf(const wchar_t* pFormat, + va_list argList) { + size_t nMaxLen = 0; for (const wchar_t* pStr = pFormat; *pStr != 0; pStr++) { if (*pStr != '%' || *(pStr = pStr + 1) == '%') { ++nMaxLen; @@ -80,7 +80,7 @@ pdfium::Optional<FX_STRSIZE> GuessSizeForVSWPrintf(const wchar_t* pFormat, ++pStr; } if (nWidth < 0 || nWidth > 128 * 1024) - return pdfium::Optional<FX_STRSIZE>(); + return pdfium::Optional<size_t>(); int nPrecision = 0; if (*pStr == '.') { pStr++; @@ -94,7 +94,7 @@ pdfium::Optional<FX_STRSIZE> GuessSizeForVSWPrintf(const wchar_t* pFormat, } } if (nPrecision < 0 || nPrecision > 128 * 1024) - return pdfium::Optional<FX_STRSIZE>(); + return pdfium::Optional<size_t>(); int nModifier = 0; if (*pStr == L'I' && *(pStr + 1) == L'6' && *(pStr + 2) == L'4') { pStr += 3; @@ -243,7 +243,7 @@ pdfium::Optional<FX_STRSIZE> GuessSizeForVSWPrintf(const wchar_t* pFormat, nMaxLen += nItemLen; } nMaxLen += 32; // Fudge factor. - return pdfium::Optional<FX_STRSIZE>(nMaxLen); + return pdfium::Optional<size_t>(nMaxLen); } #ifndef NDEBUG @@ -293,7 +293,7 @@ WideString::WideString(WideString&& other) noexcept { m_pData.Swap(other.m_pData); } -WideString::WideString(const wchar_t* pStr, FX_STRSIZE nLen) { +WideString::WideString(const wchar_t* pStr, size_t nLen) { if (nLen) m_pData.Reset(StringData::Create(pStr, nLen)); } @@ -317,7 +317,7 @@ WideString::WideString(const WideStringView& str1, const WideStringView& str2) { FX_SAFE_STRSIZE nSafeLen = str1.GetLength(); nSafeLen += str2.GetLength(); - FX_STRSIZE nNewLen = nSafeLen.ValueOrDie(); + size_t nNewLen = nSafeLen.ValueOrDie(); if (nNewLen == 0) return; @@ -332,13 +332,13 @@ WideString::WideString(const std::initializer_list<WideStringView>& list) { for (const auto& item : list) nSafeLen += item.GetLength(); - FX_STRSIZE nNewLen = nSafeLen.ValueOrDie(); + size_t nNewLen = nSafeLen.ValueOrDie(); if (nNewLen == 0) return; m_pData.Reset(StringData::Create(nNewLen)); - FX_STRSIZE nOffset = 0; + size_t nOffset = 0; for (const auto& item : list) { m_pData->CopyContentsAt(nOffset, item.unterminated_c_str(), item.GetLength()); @@ -443,13 +443,13 @@ bool WideString::operator<(const WideString& str) const { return result < 0 || (result == 0 && GetLength() < str.GetLength()); } -void WideString::AssignCopy(const wchar_t* pSrcData, FX_STRSIZE nSrcLen) { +void WideString::AssignCopy(const wchar_t* pSrcData, size_t nSrcLen) { AllocBeforeWrite(nSrcLen); m_pData->CopyContents(pSrcData, nSrcLen); m_pData->m_nDataLength = nSrcLen; } -void WideString::ReallocBeforeWrite(FX_STRSIZE nNewLength) { +void WideString::ReallocBeforeWrite(size_t nNewLength) { if (m_pData && m_pData->CanOperateInPlace(nNewLength)) return; @@ -460,7 +460,7 @@ void WideString::ReallocBeforeWrite(FX_STRSIZE nNewLength) { RetainPtr<StringData> pNewData(StringData::Create(nNewLength)); if (m_pData) { - FX_STRSIZE nCopyLength = std::min(m_pData->m_nDataLength, nNewLength); + size_t nCopyLength = std::min(m_pData->m_nDataLength, nNewLength); pNewData->CopyContents(m_pData->m_String, nCopyLength); pNewData->m_nDataLength = nCopyLength; } else { @@ -470,7 +470,7 @@ void WideString::ReallocBeforeWrite(FX_STRSIZE nNewLength) { m_pData.Swap(pNewData); } -void WideString::AllocBeforeWrite(FX_STRSIZE nNewLength) { +void WideString::AllocBeforeWrite(size_t nNewLength) { if (m_pData && m_pData->CanOperateInPlace(nNewLength)) return; @@ -482,7 +482,7 @@ void WideString::AllocBeforeWrite(FX_STRSIZE nNewLength) { m_pData.Reset(StringData::Create(nNewLength)); } -void WideString::ReleaseBuffer(FX_STRSIZE nNewLength) { +void WideString::ReleaseBuffer(size_t nNewLength) { if (!m_pData) return; @@ -503,11 +503,11 @@ void WideString::ReleaseBuffer(FX_STRSIZE nNewLength) { } } -void WideString::Reserve(FX_STRSIZE len) { +void WideString::Reserve(size_t len) { GetBuffer(len); } -wchar_t* WideString::GetBuffer(FX_STRSIZE nMinBufLength) { +wchar_t* WideString::GetBuffer(size_t nMinBufLength) { if (!m_pData) { if (nMinBufLength == 0) return nullptr; @@ -532,28 +532,28 @@ wchar_t* WideString::GetBuffer(FX_STRSIZE nMinBufLength) { return m_pData->m_String; } -FX_STRSIZE WideString::Delete(FX_STRSIZE index, FX_STRSIZE count) { +size_t WideString::Delete(size_t index, size_t count) { if (!m_pData) return 0; - FX_STRSIZE old_length = m_pData->m_nDataLength; + size_t old_length = m_pData->m_nDataLength; if (count == 0 || - index != pdfium::clamp(index, static_cast<FX_STRSIZE>(0), old_length)) + index != pdfium::clamp(index, static_cast<size_t>(0), old_length)) return old_length; - FX_STRSIZE removal_length = index + count; + size_t removal_length = index + count; if (removal_length > old_length) return old_length; ReallocBeforeWrite(old_length); - FX_STRSIZE chars_to_copy = old_length - removal_length + 1; + size_t chars_to_copy = old_length - removal_length + 1; wmemmove(m_pData->m_String + index, m_pData->m_String + removal_length, chars_to_copy); m_pData->m_nDataLength = old_length - count; return m_pData->m_nDataLength; } -void WideString::Concat(const wchar_t* pSrcData, FX_STRSIZE nSrcLen) { +void WideString::Concat(const wchar_t* pSrcData, size_t nSrcLen) { if (!pSrcData || nSrcLen == 0) return; @@ -596,7 +596,7 @@ ByteString WideString::UTF16LE_Encode() const { return result; } -WideString WideString::Mid(FX_STRSIZE first, FX_STRSIZE count) const { +WideString WideString::Mid(size_t first, size_t count) const { if (!m_pData) return WideString(); @@ -617,21 +617,21 @@ WideString WideString::Mid(FX_STRSIZE first, FX_STRSIZE count) const { return dest; } -WideString WideString::Left(FX_STRSIZE count) const { +WideString WideString::Left(size_t count) const { if (count == 0 || !IsValidLength(count)) return WideString(); return Mid(0, count); } -WideString WideString::Right(FX_STRSIZE count) const { +WideString WideString::Right(size_t count) const { if (count == 0 || !IsValidLength(count)) return WideString(); return Mid(GetLength() - count, count); } void WideString::AllocCopy(WideString& dest, - FX_STRSIZE nCopyLen, - FX_STRSIZE nCopyIndex) const { + size_t nCopyLen, + size_t nCopyIndex) const { if (nCopyLen == 0) return; @@ -640,7 +640,7 @@ void WideString::AllocCopy(WideString& dest, dest.m_pData.Swap(pNewData); } -bool WideString::TryVSWPrintf(FX_STRSIZE size, +bool WideString::TryVSWPrintf(size_t size, const wchar_t* pFormat, va_list argList) { GetBuffer(size); @@ -676,7 +676,7 @@ void WideString::FormatV(const wchar_t* format, va_list argList) { while (maxLen < 32 * 1024) { va_copy(argListCopy, argList); bool bSufficientBuffer = - TryVSWPrintf(static_cast<FX_STRSIZE>(maxLen), format, argListCopy); + TryVSWPrintf(static_cast<size_t>(maxLen), format, argListCopy); va_end(argListCopy); if (bSufficientBuffer) break; @@ -691,12 +691,12 @@ void WideString::Format(const wchar_t* pFormat, ...) { va_end(argList); } -FX_STRSIZE WideString::Insert(FX_STRSIZE location, wchar_t ch) { - const FX_STRSIZE cur_length = m_pData ? m_pData->m_nDataLength : 0; +size_t WideString::Insert(size_t location, wchar_t ch) { + const size_t cur_length = m_pData ? m_pData->m_nDataLength : 0; if (!IsValidLength(location)) return cur_length; - const FX_STRSIZE new_length = cur_length + 1; + const size_t new_length = cur_length + 1; ReallocBeforeWrite(new_length); wmemmove(m_pData->m_String + location + 1, m_pData->m_String + location, new_length - location); @@ -705,35 +705,34 @@ FX_STRSIZE WideString::Insert(FX_STRSIZE location, wchar_t ch) { return new_length; } -pdfium::Optional<FX_STRSIZE> WideString::Find(wchar_t ch, - FX_STRSIZE start) const { +pdfium::Optional<size_t> WideString::Find(wchar_t ch, size_t start) const { if (!m_pData) - return pdfium::Optional<FX_STRSIZE>(); + return pdfium::Optional<size_t>(); if (!IsValidIndex(start)) - return pdfium::Optional<FX_STRSIZE>(); + return pdfium::Optional<size_t>(); const wchar_t* pStr = wmemchr(m_pData->m_String + start, ch, m_pData->m_nDataLength - start); - return pStr ? pdfium::Optional<FX_STRSIZE>( - static_cast<FX_STRSIZE>(pStr - m_pData->m_String)) - : pdfium::Optional<FX_STRSIZE>(); + return pStr ? pdfium::Optional<size_t>( + static_cast<size_t>(pStr - m_pData->m_String)) + : pdfium::Optional<size_t>(); } -pdfium::Optional<FX_STRSIZE> WideString::Find(const WideStringView& subStr, - FX_STRSIZE start) const { +pdfium::Optional<size_t> WideString::Find(const WideStringView& subStr, + size_t start) const { if (!m_pData) - return pdfium::Optional<FX_STRSIZE>(); + return pdfium::Optional<size_t>(); if (!IsValidIndex(start)) - return pdfium::Optional<FX_STRSIZE>(); + return pdfium::Optional<size_t>(); const wchar_t* pStr = FX_wcsstr(m_pData->m_String + start, m_pData->m_nDataLength - start, subStr.unterminated_c_str(), subStr.GetLength()); - return pStr ? pdfium::Optional<FX_STRSIZE>( - static_cast<FX_STRSIZE>(pStr - m_pData->m_String)) - : pdfium::Optional<FX_STRSIZE>(); + return pStr ? pdfium::Optional<size_t>( + static_cast<size_t>(pStr - m_pData->m_String)) + : pdfium::Optional<size_t>(); } void WideString::MakeLower() { @@ -752,7 +751,7 @@ void WideString::MakeUpper() { FXSYS_wcsupr(m_pData->m_String); } -FX_STRSIZE WideString::Remove(wchar_t chRemove) { +size_t WideString::Remove(wchar_t chRemove) { if (!m_pData || m_pData->m_nDataLength < 1) return 0; @@ -781,24 +780,25 @@ FX_STRSIZE WideString::Remove(wchar_t chRemove) { } *pstrDest = 0; - FX_STRSIZE count = static_cast<FX_STRSIZE>(pstrSource - pstrDest); + size_t count = static_cast<size_t>(pstrSource - pstrDest); m_pData->m_nDataLength -= count; return count; } -FX_STRSIZE WideString::Replace(const WideStringView& pOld, - const WideStringView& pNew) { +size_t WideString::Replace(const WideStringView& pOld, + const WideStringView& pNew) { if (!m_pData || pOld.IsEmpty()) return 0; - FX_STRSIZE nSourceLen = pOld.GetLength(); - FX_STRSIZE nReplacementLen = pNew.GetLength(); - FX_STRSIZE count = 0; + size_t nSourceLen = pOld.GetLength(); + size_t nReplacementLen = pNew.GetLength(); + size_t count = 0; const wchar_t* pStart = m_pData->m_String; wchar_t* pEnd = m_pData->m_String + m_pData->m_nDataLength; while (1) { - const wchar_t* pTarget = FX_wcsstr(pStart, (FX_STRSIZE)(pEnd - pStart), - pOld.unterminated_c_str(), nSourceLen); + const wchar_t* pTarget = + FX_wcsstr(pStart, static_cast<size_t>(pEnd - pStart), + pOld.unterminated_c_str(), nSourceLen); if (!pTarget) break; @@ -808,7 +808,7 @@ FX_STRSIZE WideString::Replace(const WideStringView& pOld, if (count == 0) return 0; - FX_STRSIZE nNewLength = + size_t nNewLength = m_pData->m_nDataLength + (nReplacementLen - nSourceLen) * count; if (nNewLength == 0) { @@ -819,9 +819,10 @@ FX_STRSIZE WideString::Replace(const WideStringView& pOld, RetainPtr<StringData> pNewData(StringData::Create(nNewLength)); pStart = m_pData->m_String; wchar_t* pDest = pNewData->m_String; - for (FX_STRSIZE i = 0; i < count; i++) { - const wchar_t* pTarget = FX_wcsstr(pStart, (FX_STRSIZE)(pEnd - pStart), - pOld.unterminated_c_str(), nSourceLen); + for (size_t i = 0; i < count; i++) { + const wchar_t* pTarget = + FX_wcsstr(pStart, static_cast<size_t>(pEnd - pStart), + pOld.unterminated_c_str(), nSourceLen); wmemcpy(pDest, pStart, pTarget - pStart); pDest += pTarget - pStart; wmemcpy(pDest, pNew.unterminated_c_str(), pNew.GetLength()); @@ -850,29 +851,28 @@ WideString WideString::FromUTF8(const ByteStringView& str) { return WideString(); CFX_UTF8Decoder decoder; - for (FX_STRSIZE i = 0; i < str.GetLength(); i++) + for (size_t i = 0; i < str.GetLength(); i++) decoder.Input(str[i]); return WideString(decoder.GetResult()); } // static -WideString WideString::FromUTF16LE(const unsigned short* wstr, - FX_STRSIZE wlen) { +WideString WideString::FromUTF16LE(const unsigned short* wstr, size_t wlen) { if (!wstr || wlen == 0) { return WideString(); } WideString result; wchar_t* buf = result.GetBuffer(wlen); - for (FX_STRSIZE i = 0; i < wlen; i++) { + for (size_t i = 0; i < wlen; i++) { buf[i] = wstr[i]; } result.ReleaseBuffer(wlen); return result; } -void WideString::SetAt(FX_STRSIZE index, wchar_t c) { +void WideString::SetAt(size_t index, wchar_t c) { ASSERT(IsValidIndex(index)); ReallocBeforeWrite(m_pData->m_nDataLength); m_pData->m_String[index] = c; @@ -894,10 +894,10 @@ int WideString::Compare(const WideString& str) const { if (!str.m_pData) { return 1; } - FX_STRSIZE this_len = m_pData->m_nDataLength; - FX_STRSIZE that_len = str.m_pData->m_nDataLength; - FX_STRSIZE min_len = std::min(this_len, that_len); - for (FX_STRSIZE i = 0; i < min_len; i++) { + size_t this_len = m_pData->m_nDataLength; + size_t that_len = str.m_pData->m_nDataLength; + size_t min_len = std::min(this_len, that_len); + for (size_t i = 0; i < min_len; i++) { if (m_pData->m_String[i] < str.m_pData->m_String[i]) { return -1; } @@ -921,8 +921,8 @@ int WideString::CompareNoCase(const wchar_t* lpsz) const { return FXSYS_wcsicmp(m_pData->m_String, lpsz); } -FX_STRSIZE WideString::WStringLength(const unsigned short* str) { - FX_STRSIZE len = 0; +size_t WideString::WStringLength(const unsigned short* str) { + size_t len = 0; if (str) while (str[len]) len++; @@ -933,7 +933,7 @@ void WideString::TrimRight(const WideStringView& pTargets) { if (IsEmpty() || pTargets.IsEmpty()) return; - FX_STRSIZE pos = GetLength(); + size_t pos = GetLength(); while (pos && pTargets.Contains(m_pData->m_String[pos - 1])) pos--; @@ -957,13 +957,13 @@ void WideString::TrimLeft(const WideStringView& pTargets) { if (!m_pData || pTargets.IsEmpty()) return; - FX_STRSIZE len = GetLength(); + size_t len = GetLength(); if (len == 0) return; - FX_STRSIZE pos = 0; + size_t pos = 0; while (pos < len) { - FX_STRSIZE i = 0; + size_t i = 0; while (i < pTargets.GetLength() && pTargets.CharAt(i) != m_pData->m_String[pos]) { i++; @@ -977,7 +977,7 @@ void WideString::TrimLeft(const WideStringView& pTargets) { return; ReallocBeforeWrite(len); - FX_STRSIZE nDataLength = len - pos; + size_t nDataLength = len - pos; memmove(m_pData->m_String, m_pData->m_String + pos, (nDataLength + 1) * sizeof(wchar_t)); m_pData->m_nDataLength = nDataLength; diff --git a/core/fxcrt/widestring.h b/core/fxcrt/widestring.h index f56703f1ab..73846e1be0 100644 --- a/core/fxcrt/widestring.h +++ b/core/fxcrt/widestring.h @@ -47,7 +47,7 @@ class WideString { // NOLINTNEXTLINE(runtime/explicit) WideString(char) = delete; - WideString(const wchar_t* ptr, FX_STRSIZE len); + WideString(const wchar_t* ptr, size_t len); explicit WideString(const WideStringView& str); WideString(const WideStringView& str1, const WideStringView& str2); @@ -59,9 +59,9 @@ class WideString { static WideString FromCodePage(const ByteStringView& str, uint16_t codepage); static WideString FromUTF8(const ByteStringView& str); - static WideString FromUTF16LE(const unsigned short* str, FX_STRSIZE len); + static WideString FromUTF16LE(const unsigned short* str, size_t len); - static FX_STRSIZE WStringLength(const unsigned short* str); + static size_t WStringLength(const unsigned short* str); // Explicit conversion to C-style wide string. // Note: Any subsequent modification of |this| will invalidate the result. @@ -89,13 +89,13 @@ class WideString { void clear() { m_pData.Reset(); } - FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } - FX_STRSIZE GetStringLength() const { + size_t GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } + size_t GetStringLength() const { return m_pData ? FXSYS_wcslen(m_pData->m_String) : 0; } bool IsEmpty() const { return !GetLength(); } - bool IsValidIndex(FX_STRSIZE index) const { return index < GetLength(); } - bool IsValidLength(FX_STRSIZE length) const { return length <= GetLength(); } + bool IsValidIndex(size_t index) const { return index < GetLength(); } + bool IsValidLength(size_t length) const { return length <= GetLength(); } const WideString& operator=(const wchar_t* str); const WideString& operator=(const WideString& stringSrc); @@ -116,7 +116,7 @@ class WideString { bool operator<(const WideString& str) const; - CharType operator[](const FX_STRSIZE index) const { + CharType operator[](const size_t index) const { ASSERT(IsValidIndex(index)); return m_pData ? m_pData->m_String[index] : 0; } @@ -124,20 +124,20 @@ class WideString { CharType First() const { return GetLength() ? (*this)[0] : 0; } CharType Last() const { return GetLength() ? (*this)[GetLength() - 1] : 0; } - void SetAt(FX_STRSIZE index, wchar_t c); + void SetAt(size_t index, wchar_t c); int Compare(const wchar_t* str) const; int Compare(const WideString& str) const; int CompareNoCase(const wchar_t* str) const; - WideString Mid(FX_STRSIZE first, FX_STRSIZE count) const; - WideString Left(FX_STRSIZE count) const; - WideString Right(FX_STRSIZE count) const; + WideString Mid(size_t first, size_t count) const; + WideString Left(size_t count) const; + WideString Right(size_t count) const; - FX_STRSIZE Insert(FX_STRSIZE index, wchar_t ch); - FX_STRSIZE InsertAtFront(wchar_t ch) { return Insert(0, ch); } - FX_STRSIZE InsertAtBack(wchar_t ch) { return Insert(GetLength(), ch); } - FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1); + size_t Insert(size_t index, wchar_t ch); + size_t InsertAtFront(wchar_t ch) { return Insert(0, ch); } + size_t InsertAtBack(wchar_t ch) { return Insert(GetLength(), ch); } + size_t Delete(size_t index, size_t count = 1); void Format(const wchar_t* lpszFormat, ...); void FormatV(const wchar_t* lpszFormat, va_list argList); @@ -153,27 +153,27 @@ class WideString { void TrimLeft(wchar_t chTarget); void TrimLeft(const WideStringView& pTargets); - void Reserve(FX_STRSIZE len); - wchar_t* GetBuffer(FX_STRSIZE len); - void ReleaseBuffer(FX_STRSIZE len); + void Reserve(size_t len); + wchar_t* GetBuffer(size_t len); + void ReleaseBuffer(size_t len); int GetInteger() const; float GetFloat() const; - pdfium::Optional<FX_STRSIZE> Find(const WideStringView& pSub, - FX_STRSIZE start = 0) const; - pdfium::Optional<FX_STRSIZE> Find(wchar_t ch, FX_STRSIZE start = 0) const; + pdfium::Optional<size_t> Find(const WideStringView& pSub, + size_t start = 0) const; + pdfium::Optional<size_t> Find(wchar_t ch, size_t start = 0) const; - bool Contains(const WideStringView& lpszSub, FX_STRSIZE start = 0) const { + bool Contains(const WideStringView& lpszSub, size_t start = 0) const { return Find(lpszSub, start).has_value(); } - bool Contains(char ch, FX_STRSIZE start = 0) const { + bool Contains(char ch, size_t start = 0) const { return Find(ch, start).has_value(); } - FX_STRSIZE Replace(const WideStringView& pOld, const WideStringView& pNew); - FX_STRSIZE Remove(wchar_t ch); + size_t Replace(const WideStringView& pOld, const WideStringView& pNew); + size_t Remove(wchar_t ch); ByteString UTF8Encode() const; ByteString UTF16LE_Encode() const; @@ -181,16 +181,14 @@ class WideString { protected: using StringData = StringDataTemplate<wchar_t>; - void ReallocBeforeWrite(FX_STRSIZE nLen); - void AllocBeforeWrite(FX_STRSIZE nLen); - void AllocCopy(WideString& dest, - FX_STRSIZE nCopyLen, - FX_STRSIZE nCopyIndex) const; - void AssignCopy(const wchar_t* pSrcData, FX_STRSIZE nSrcLen); - void Concat(const wchar_t* lpszSrcData, FX_STRSIZE nSrcLen); + void ReallocBeforeWrite(size_t nLen); + void AllocBeforeWrite(size_t nLen); + void AllocCopy(WideString& dest, size_t nCopyLen, size_t nCopyIndex) const; + void AssignCopy(const wchar_t* pSrcData, size_t nSrcLen); + void Concat(const wchar_t* lpszSrcData, size_t nSrcLen); // Returns true unless we ran out of space. - bool TryVSWPrintf(FX_STRSIZE size, const wchar_t* format, va_list argList); + bool TryVSWPrintf(size_t size, const wchar_t* format, va_list argList); RetainPtr<StringData> m_pData; diff --git a/core/fxcrt/widestring_unittest.cpp b/core/fxcrt/widestring_unittest.cpp index 5eba72eea7..1f7219616d 100644 --- a/core/fxcrt/widestring_unittest.cpp +++ b/core/fxcrt/widestring_unittest.cpp @@ -510,7 +510,7 @@ TEST(WideString, Find) { EXPECT_FALSE(empty_string.Find(L'a').has_value()); EXPECT_FALSE(empty_string.Find(L'\0').has_value()); - pdfium::Optional<FX_STRSIZE> result; + pdfium::Optional<size_t> result; WideString single_string(L"a"); result = single_string.Find(L'a'); ASSERT_TRUE(result.has_value()); @@ -1017,7 +1017,7 @@ TEST(WideStringView, Find) { EXPECT_FALSE(empty_string.Find(L'a').has_value()); EXPECT_FALSE(empty_string.Find(L'\0').has_value()); - pdfium::Optional<FX_STRSIZE> result; + pdfium::Optional<size_t> result; WideStringView single_string(L"a"); result = single_string.Find(L'a'); ASSERT_TRUE(result.has_value()); diff --git a/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp b/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp index 5dcb867623..2d1d3d7a08 100644 --- a/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp +++ b/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp @@ -103,7 +103,7 @@ CFX_XMLSyntaxParser::CFX_XMLSyntaxParser( m_iXMLPlaneSize = std::min(m_iXMLPlaneSize, - pdfium::base::checked_cast<FX_STRSIZE>(m_pStream->GetLength())); + pdfium::base::checked_cast<size_t>(m_pStream->GetLength())); m_iCurrentPos = m_pStream->GetBOMLength(); FX_SAFE_STRSIZE alloc_size_safe = m_iXMLPlaneSize; diff --git a/core/fxcrt/xml/cfx_xmlsyntaxparser.h b/core/fxcrt/xml/cfx_xmlsyntaxparser.h index 8379aa445b..b93bbb6801 100644 --- a/core/fxcrt/xml/cfx_xmlsyntaxparser.h +++ b/core/fxcrt/xml/cfx_xmlsyntaxparser.h @@ -101,14 +101,14 @@ class CFX_XMLSyntaxParser { void ParseTextChar(wchar_t ch); RetainPtr<CFX_SeekableStreamProxy> m_pStream; - FX_STRSIZE m_iXMLPlaneSize; + size_t m_iXMLPlaneSize; FX_FILESIZE m_iCurrentPos; int32_t m_iCurrentNodeNum; int32_t m_iLastNodeNum; int32_t m_iParsedBytes; FX_FILESIZE m_ParsedChars; std::vector<wchar_t> m_Buffer; - FX_STRSIZE m_iBufferChars; + size_t m_iBufferChars; bool m_bEOS; FX_FILESIZE m_Start; // Start position in m_Buffer FX_FILESIZE m_End; // End position in m_Buffer diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp index 4be35668e0..af1d58f696 100644 --- a/core/fxge/android/cfpf_skiafontmgr.cpp +++ b/core/fxge/android/cfpf_skiafontmgr.cpp @@ -37,7 +37,8 @@ static unsigned long FPF_SkiaStream_Read(FXFT_Stream stream, if (!pFileRead) return 0; - if (!pFileRead->ReadBlock(buffer, (FX_FILESIZE)offset, (size_t)count)) + if (!pFileRead->ReadBlock(buffer, (FX_FILESIZE)offset, + static_cast<size_t>(count))) return 0; return count; diff --git a/core/fxge/apple/fx_quartz_device.cpp b/core/fxge/apple/fx_quartz_device.cpp index b24638c465..4ab6620485 100644 --- a/core/fxge/apple/fx_quartz_device.cpp +++ b/core/fxge/apple/fx_quartz_device.cpp @@ -49,7 +49,7 @@ void CQuartz2D::destroyGraphics(void* graphics) { void* CQuartz2D::CreateFont(const uint8_t* pFontData, uint32_t dwFontSize) { CGDataProviderRef pDataProvider = CGDataProviderCreateWithData( - nullptr, pFontData, (size_t)dwFontSize, nullptr); + nullptr, pFontData, static_cast<size_t>(dwFontSize), nullptr); if (!pDataProvider) return nullptr; diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp index 9a617da32f..d97391822a 100644 --- a/core/fxge/win32/cfx_psrenderer.cpp +++ b/core/fxge/win32/cfx_psrenderer.cpp @@ -458,7 +458,7 @@ bool CFX_PSRenderer::DrawDIBits(const RetainPtr<CFX_DIBSource>& pSource, int bpp = pConverted->GetBPP() / 8; uint8_t* output_buf = nullptr; - FX_STRSIZE output_size = 0; + size_t output_size = 0; const char* filter = nullptr; if ((m_PSLevel == 2 || flags & FXRENDER_IMAGE_LOSSY) && CCodec_JpegModule::JpegEncode(pConverted, &output_buf, &output_size)) { diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index 9957239089..35f9a5fce5 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp @@ -610,7 +610,7 @@ void* CFX_Win32FontInfo::MapFont(int weight, const unsigned short* pName = reinterpret_cast<const unsigned short*>( g_VariantNames[i].m_pVariantName); - FX_STRSIZE len = WideString::WStringLength(pName); + size_t len = WideString::WStringLength(pName); WideString wsName = WideString::FromUTF16LE(pName, len); if (wsFace == wsName) return hFont; |