From 8b1408e7053247def45659515cda19a64a7fccd5 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 27 Sep 2017 11:07:51 -0400 Subject: Remove FXSYS_strlen and FXSYS_wcslen With the conversion of internal string sizes to size_t, these wrappers are no longer needed. Replacing them with strlen and wcslen respectively. BUG=pdfium:828 Change-Id: Ia087ca2ddaf688a57ec9bd9ddfb8533cbe41510d Reviewed-on: https://pdfium-review.googlesource.com/14890 Commit-Queue: Ryan Harrison Reviewed-by: dsinclair --- core/fpdfapi/edit/cpdf_creator.cpp | 6 +++--- core/fpdfapi/parser/fpdf_parser_decode.cpp | 2 +- core/fpdftext/cpdf_textpagefind.cpp | 4 ++-- core/fxcodec/codec/ccodec_pngmodule.cpp | 6 +++--- core/fxcodec/codec/ccodec_tiffmodule.cpp | 2 +- core/fxcrt/bytestring.cpp | 8 ++++---- core/fxcrt/bytestring.h | 2 +- core/fxcrt/bytestring_unittest.cpp | 2 +- core/fxcrt/cfx_widetextbuf.cpp | 4 ++-- core/fxcrt/css/cfx_cssstylesheet_unittest.cpp | 14 +++++++------- core/fxcrt/fx_extension.cpp | 2 +- core/fxcrt/fx_string.cpp | 2 +- core/fxcrt/fx_system.h | 10 ++-------- core/fxcrt/widestring.cpp | 16 ++++++++-------- core/fxcrt/widestring.h | 2 +- core/fxcrt/widestring_unittest.cpp | 2 +- core/fxcrt/xml/cfx_xmlnode.cpp | 2 +- core/fxge/android/cfpf_skiafontdescriptor.cpp | 2 +- core/fxge/android/cfpf_skiafontmgr.cpp | 2 +- core/fxge/android/cfpf_skiapathfont.cpp | 2 +- 20 files changed, 43 insertions(+), 49 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp index 7c567779ff..5f209a634f 100644 --- a/core/fpdfapi/edit/cpdf_creator.cpp +++ b/core/fpdfapi/edit/cpdf_creator.cpp @@ -102,7 +102,7 @@ bool CFX_FileBufferArchive::WriteByte(uint8_t byte) { bool CFX_FileBufferArchive::WriteDWord(uint32_t i) { char buf[32]; FXSYS_itoa(i, buf, 10); - return WriteBlock(buf, static_cast(FXSYS_strlen(buf))); + return WriteBlock(buf, static_cast(strlen(buf))); } bool CFX_FileBufferArchive::WriteString(const ByteStringView& str) { @@ -687,7 +687,7 @@ int32_t CPDF_Creator::WriteDoc_Stage4() { char offset_buf[20]; memset(offset_buf, 0, sizeof(offset_buf)); FXSYS_i64toa(prev, offset_buf, 10); - if (!m_Archive->WriteBlock(offset_buf, FXSYS_strlen(offset_buf))) + if (!m_Archive->WriteBlock(offset_buf, strlen(offset_buf))) return -1; } } @@ -749,7 +749,7 @@ int32_t CPDF_Creator::WriteDoc_Stage4() { char offset_buf[20]; memset(offset_buf, 0, sizeof(offset_buf)); FXSYS_i64toa(m_XrefStart, offset_buf, 10); - if (!m_Archive->WriteBlock(offset_buf, FXSYS_strlen(offset_buf)) || + if (!m_Archive->WriteBlock(offset_buf, strlen(offset_buf)) || !m_Archive->WriteString("\r\n%%EOF\r\n")) { return -1; } diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp index 228c012e5f..7ad6c0176f 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp @@ -465,7 +465,7 @@ WideString PDF_DecodeText(const ByteString& bstr) { ByteString PDF_EncodeText(const wchar_t* pString, int len) { if (len == -1) - len = FXSYS_wcslen(pString); + len = wcslen(pString); ByteString result; char* dest_buf1 = result.GetBuffer(len); diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp index 9f9be202d6..a874521326 100644 --- a/core/fpdftext/cpdf_textpagefind.cpp +++ b/core/fpdftext/cpdf_textpagefind.cpp @@ -376,8 +376,8 @@ bool CPDF_TextPageFind::ExtractSubString(WideString& rString, lpszFullString++; } const wchar_t* lpchEnd = std::wcschr(lpszFullString, chSep); - int nLen = lpchEnd ? (int)(lpchEnd - lpszFullString) - : (int)FXSYS_wcslen(lpszFullString); + int nLen = + lpchEnd ? (int)(lpchEnd - lpszFullString) : (int)wcslen(lpszFullString); ASSERT(nLen >= 0); memcpy(rString.GetBuffer(nLen), lpszFullString, nLen * sizeof(wchar_t)); rString.ReleaseBuffer(rString.GetStringLength()); diff --git a/core/fxcodec/codec/ccodec_pngmodule.cpp b/core/fxcodec/codec/ccodec_pngmodule.cpp index d500745ca7..0531ff10b1 100644 --- a/core/fxcodec/codec/ccodec_pngmodule.cpp +++ b/core/fxcodec/codec/ccodec_pngmodule.cpp @@ -80,11 +80,11 @@ static void _png_load_bmp_attribute(png_structp png_ptr, png_textp text = nullptr; png_get_text(png_ptr, info_ptr, &text, &num_text); for (i = 0; i < num_text; i++) { - len = FXSYS_strlen(text[i].key); + len = strlen(text[i].key); buf = "Time"; - if (memcmp(buf, text[i].key, std::min(len, FXSYS_strlen(buf)))) { + if (memcmp(buf, text[i].key, std::min(len, strlen(buf)))) { buf = "Author"; - if (!memcmp(buf, text[i].key, std::min(len, FXSYS_strlen(buf)))) { + if (!memcmp(buf, text[i].key, std::min(len, strlen(buf)))) { pAttribute->m_strAuthor = text[i].text_length > 0 ? ByteString(reinterpret_cast(text[i].text), diff --git a/core/fxcodec/codec/ccodec_tiffmodule.cpp b/core/fxcodec/codec/ccodec_tiffmodule.cpp index f11c480bd7..0fcd9f3a99 100644 --- a/core/fxcodec/codec/ccodec_tiffmodule.cpp +++ b/core/fxcodec/codec/ccodec_tiffmodule.cpp @@ -201,7 +201,7 @@ void Tiff_Exif_GetStringInfo(TIFF* tif_ctx, TIFFGetField(tif_ctx, tag, &buf); if (!buf) return; - size_t size = FXSYS_strlen(buf); + size_t size = strlen(buf); uint8_t* ptr = FX_Alloc(uint8_t, size + 1); memcpy(ptr, buf, size); ptr[size] = 0; diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp index 3079eb7b72..37121a7da9 100644 --- a/core/fxcrt/bytestring.cpp +++ b/core/fxcrt/bytestring.cpp @@ -116,7 +116,7 @@ ByteString::ByteString(char ch) { } ByteString::ByteString(const char* ptr) - : ByteString(ptr, ptr ? FXSYS_strlen(ptr) : 0) {} + : ByteString(ptr, ptr ? strlen(ptr) : 0) {} ByteString::ByteString(const ByteStringView& stringSrc) { if (!stringSrc.IsEmpty()) @@ -169,7 +169,7 @@ const ByteString& ByteString::operator=(const char* pStr) { if (!pStr || !pStr[0]) clear(); else - AssignCopy(pStr, FXSYS_strlen(pStr)); + AssignCopy(pStr, strlen(pStr)); return *this; } @@ -192,7 +192,7 @@ const ByteString& ByteString::operator=(const ByteString& stringSrc) { const ByteString& ByteString::operator+=(const char* pStr) { if (pStr) - Concat(pStr, FXSYS_strlen(pStr)); + Concat(pStr, strlen(pStr)); return *this; } @@ -223,7 +223,7 @@ bool ByteString::operator==(const char* ptr) const { if (!ptr) return m_pData->m_nDataLength == 0; - return FXSYS_strlen(ptr) == m_pData->m_nDataLength && + return strlen(ptr) == m_pData->m_nDataLength && memcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0; } diff --git a/core/fxcrt/bytestring.h b/core/fxcrt/bytestring.h index 2b01bc19aa..67fdd1d9ac 100644 --- a/core/fxcrt/bytestring.h +++ b/core/fxcrt/bytestring.h @@ -93,7 +93,7 @@ class ByteString { 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; + return m_pData ? strlen(m_pData->m_String) : 0; } bool IsEmpty() const { return !GetLength(); } bool IsValidIndex(size_t index) const { return index < GetLength(); } diff --git a/core/fxcrt/bytestring_unittest.cpp b/core/fxcrt/bytestring_unittest.cpp index d3597ad421..ed20abcc8e 100644 --- a/core/fxcrt/bytestring_unittest.cpp +++ b/core/fxcrt/bytestring_unittest.cpp @@ -1421,7 +1421,7 @@ TEST(ByteString, Empty) { EXPECT_TRUE(empty_str.IsEmpty()); EXPECT_EQ(0u, empty_str.GetLength()); const char* cstr = empty_str.c_str(); - EXPECT_EQ(0u, FXSYS_strlen(cstr)); + EXPECT_EQ(0u, strlen(cstr)); } TEST(ByteString, InitializerList) { diff --git a/core/fxcrt/cfx_widetextbuf.cpp b/core/fxcrt/cfx_widetextbuf.cpp index 08e4921560..a9b59b5ff8 100644 --- a/core/fxcrt/cfx_widetextbuf.cpp +++ b/core/fxcrt/cfx_widetextbuf.cpp @@ -29,7 +29,7 @@ CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const WideString& str) { CFX_WideTextBuf& CFX_WideTextBuf::operator<<(int i) { char buf[32]; FXSYS_itoa(i, buf, 10); - size_t len = FXSYS_strlen(buf); + size_t len = strlen(buf); ExpandBuf(len * sizeof(wchar_t)); wchar_t* str = (wchar_t*)(m_pBuffer.get() + m_DataSize); for (size_t j = 0; j < len; j++) { @@ -52,7 +52,7 @@ CFX_WideTextBuf& CFX_WideTextBuf::operator<<(double f) { } CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const wchar_t* lpsz) { - AppendBlock(lpsz, FXSYS_wcslen(lpsz) * sizeof(wchar_t)); + AppendBlock(lpsz, wcslen(lpsz) * sizeof(wchar_t)); return *this; } diff --git a/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp b/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp index 30298243bc..baa002b05c 100644 --- a/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp +++ b/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp @@ -32,7 +32,7 @@ class CFX_CSSStyleSheetTest : public testing::Test { size_t decl_count) { ASSERT(sheet_); - EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); + EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf))); EXPECT_EQ(sheet_->CountRules(), 1); CFX_CSSStyleRule* style = sheet_->GetRule(0); @@ -89,7 +89,7 @@ class CFX_CSSStyleSheetTest : public testing::Test { TEST_F(CFX_CSSStyleSheetTest, ParseMultipleSelectors) { const wchar_t* buf = L"a { border: 10px; }\nb { text-decoration: underline; }"; - EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); + EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf))); EXPECT_EQ(2, sheet_->CountRules()); CFX_CSSStyleRule* style = sheet_->GetRule(0); @@ -137,7 +137,7 @@ TEST_F(CFX_CSSStyleSheetTest, ParseMultipleSelectors) { TEST_F(CFX_CSSStyleSheetTest, ParseChildSelectors) { const wchar_t* buf = L"a b c { border: 10px; }"; - EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); + EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf))); EXPECT_EQ(1, sheet_->CountRules()); CFX_CSSStyleRule* style = sheet_->GetRule(0); @@ -172,19 +172,19 @@ TEST_F(CFX_CSSStyleSheetTest, ParseChildSelectors) { TEST_F(CFX_CSSStyleSheetTest, ParseUnhandledSelectors) { const wchar_t* buf = L"a > b { padding: 0; }"; - EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); + EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf))); EXPECT_EQ(0, sheet_->CountRules()); buf = L"a[first] { padding: 0; }"; - EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); + EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf))); EXPECT_EQ(0, sheet_->CountRules()); buf = L"a+b { padding: 0; }"; - EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); + EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf))); EXPECT_EQ(0, sheet_->CountRules()); buf = L"a ^ b { padding: 0; }"; - EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); + EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf))); EXPECT_EQ(0, sheet_->CountRules()); } diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp index 4d0adb86ca..62cf8a0e04 100644 --- a/core/fxcrt/fx_extension.cpp +++ b/core/fxcrt/fx_extension.cpp @@ -12,7 +12,7 @@ float FXSYS_wcstof(const wchar_t* pwsStr, int32_t iLength, int32_t* pUsedLen) { ASSERT(pwsStr); if (iLength < 0) - iLength = static_cast(FXSYS_wcslen(pwsStr)); + iLength = static_cast(wcslen(pwsStr)); if (iLength == 0) return 0.0f; diff --git a/core/fxcrt/fx_string.cpp b/core/fxcrt/fx_string.cpp index 233c5e64b7..13eb3a5bdd 100644 --- a/core/fxcrt/fx_string.cpp +++ b/core/fxcrt/fx_string.cpp @@ -214,7 +214,7 @@ size_t FX_ftoa(float d, char* buf) { } int i = scaled / scale; FXSYS_itoa(i, buf2, 10); - size_t len = FXSYS_strlen(buf2); + size_t len = strlen(buf2); memcpy(buf + buf_size, buf2, len); buf_size += len; int fraction = scaled % scale; diff --git a/core/fxcrt/fx_system.h b/core/fxcrt/fx_system.h index 2c84b02238..aa9b8490f9 100644 --- a/core/fxcrt/fx_system.h +++ b/core/fxcrt/fx_system.h @@ -116,16 +116,13 @@ extern "C" { #include "third_party/base/numerics/safe_conversions.h" -#define FXSYS_strlen(ptr) (strlen(ptr)) -#define FXSYS_wcslen(ptr) (wcslen(ptr)) - // Overloaded functions for C++ templates inline size_t FXSYS_len(const char* ptr) { - return FXSYS_strlen(ptr); + return strlen(ptr); } inline size_t FXSYS_len(const wchar_t* ptr) { - return FXSYS_wcslen(ptr); + return wcslen(ptr); } inline int FXSYS_cmp(const char* ptr1, const char* ptr2, size_t len) { @@ -145,9 +142,6 @@ inline const wchar_t* FXSYS_chr(const wchar_t* ptr, wchar_t ch, size_t len) { } extern "C" { -#else -#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/widestring.cpp b/core/fxcrt/widestring.cpp index b9d6dc2080..adeb28cc16 100644 --- a/core/fxcrt/widestring.cpp +++ b/core/fxcrt/widestring.cpp @@ -135,7 +135,7 @@ pdfium::Optional GuessSizeForVSWPrintf(const wchar_t* pFormat, case 's': { const wchar_t* pstrNextArg = va_arg(argList, const wchar_t*); if (pstrNextArg) { - nItemLen = FXSYS_wcslen(pstrNextArg); + nItemLen = wcslen(pstrNextArg); if (nItemLen < 1) { nItemLen = 1; } @@ -146,7 +146,7 @@ pdfium::Optional GuessSizeForVSWPrintf(const wchar_t* pFormat, case 'S': { const char* pstrNextArg = va_arg(argList, const char*); if (pstrNextArg) { - nItemLen = FXSYS_strlen(pstrNextArg); + nItemLen = strlen(pstrNextArg); if (nItemLen < 1) { nItemLen = 1; } @@ -158,7 +158,7 @@ pdfium::Optional GuessSizeForVSWPrintf(const wchar_t* pFormat, case 'S' | FORCE_ANSI: { const char* pstrNextArg = va_arg(argList, const char*); if (pstrNextArg) { - nItemLen = FXSYS_strlen(pstrNextArg); + nItemLen = strlen(pstrNextArg); if (nItemLen < 1) { nItemLen = 1; } @@ -170,7 +170,7 @@ pdfium::Optional GuessSizeForVSWPrintf(const wchar_t* pFormat, case 'S' | FORCE_UNICODE: { const wchar_t* pstrNextArg = va_arg(argList, wchar_t*); if (pstrNextArg) { - nItemLen = FXSYS_wcslen(pstrNextArg); + nItemLen = wcslen(pstrNextArg); if (nItemLen < 1) { nItemLen = 1; } @@ -225,7 +225,7 @@ pdfium::Optional GuessSizeForVSWPrintf(const wchar_t* pFormat, f = va_arg(argList, double); FXSYS_snprintf(pszTemp, sizeof(pszTemp), "%*.*f", nWidth, nPrecision + 6, f); - nItemLen = FXSYS_strlen(pszTemp); + nItemLen = strlen(pszTemp); } break; case 'p': @@ -304,7 +304,7 @@ WideString::WideString(wchar_t ch) { } WideString::WideString(const wchar_t* ptr) - : WideString(ptr, ptr ? FXSYS_wcslen(ptr) : 0) {} + : WideString(ptr, ptr ? wcslen(ptr) : 0) {} WideString::WideString(const WideStringView& stringSrc) { if (!stringSrc.IsEmpty()) { @@ -352,7 +352,7 @@ const WideString& WideString::operator=(const wchar_t* pStr) { if (!pStr || !pStr[0]) clear(); else - AssignCopy(pStr, FXSYS_wcslen(pStr)); + AssignCopy(pStr, wcslen(pStr)); return *this; } @@ -375,7 +375,7 @@ const WideString& WideString::operator=(const WideString& stringSrc) { const WideString& WideString::operator+=(const wchar_t* pStr) { if (pStr) - Concat(pStr, FXSYS_wcslen(pStr)); + Concat(pStr, wcslen(pStr)); return *this; } diff --git a/core/fxcrt/widestring.h b/core/fxcrt/widestring.h index 73846e1be0..745fa5b2ab 100644 --- a/core/fxcrt/widestring.h +++ b/core/fxcrt/widestring.h @@ -91,7 +91,7 @@ class WideString { 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; + return m_pData ? wcslen(m_pData->m_String) : 0; } bool IsEmpty() const { return !GetLength(); } bool IsValidIndex(size_t index) const { return index < GetLength(); } diff --git a/core/fxcrt/widestring_unittest.cpp b/core/fxcrt/widestring_unittest.cpp index 1f7219616d..7824c2bd72 100644 --- a/core/fxcrt/widestring_unittest.cpp +++ b/core/fxcrt/widestring_unittest.cpp @@ -1268,7 +1268,7 @@ TEST(WideString, Empty) { EXPECT_TRUE(empty_str.IsEmpty()); EXPECT_EQ(0u, empty_str.GetLength()); const wchar_t* cstr = empty_str.c_str(); - EXPECT_EQ(0u, FXSYS_wcslen(cstr)); + EXPECT_EQ(0u, wcslen(cstr)); } TEST(CFX_WidString, InitializerList) { diff --git a/core/fxcrt/xml/cfx_xmlnode.cpp b/core/fxcrt/xml/cfx_xmlnode.cpp index a1e3ac2740..4550d5b4ae 100644 --- a/core/fxcrt/xml/cfx_xmlnode.cpp +++ b/core/fxcrt/xml/cfx_xmlnode.cpp @@ -79,7 +79,7 @@ CFX_XMLNode* CFX_XMLNode::GetPath(const wchar_t* pPath, bool bQualifiedName) const { ASSERT(pPath); if (iLength < 0) { - iLength = FXSYS_wcslen(pPath); + iLength = wcslen(pPath); } if (iLength == 0) { return nullptr; diff --git a/core/fxge/android/cfpf_skiafontdescriptor.cpp b/core/fxge/android/cfpf_skiafontdescriptor.cpp index 0c5210795c..8dd4481a7d 100644 --- a/core/fxge/android/cfpf_skiafontdescriptor.cpp +++ b/core/fxge/android/cfpf_skiafontdescriptor.cpp @@ -25,7 +25,7 @@ int32_t CFPF_SkiaFontDescriptor::GetType() const { void CFPF_SkiaFontDescriptor::SetFamily(const char* pFamily) { FX_Free(m_pFamily); - int32_t iSize = FXSYS_strlen(pFamily); + int32_t iSize = strlen(pFamily); m_pFamily = FX_Alloc(char, iSize + 1); memcpy(m_pFamily, pFamily, iSize * sizeof(char)); m_pFamily[iSize] = 0; diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp index af1d58f696..214e718e0b 100644 --- a/core/fxge/android/cfpf_skiafontmgr.cpp +++ b/core/fxge/android/cfpf_skiafontmgr.cpp @@ -93,7 +93,7 @@ uint32_t FPF_GetHashCode_StringA(const char* pStr, int32_t iLength) { if (!pStr) return 0; if (iLength < 0) - iLength = FXSYS_strlen(pStr); + iLength = strlen(pStr); const char* pStrEnd = pStr + iLength; uint32_t uHashCode = 0; while (pStr < pStrEnd) diff --git a/core/fxge/android/cfpf_skiapathfont.cpp b/core/fxge/android/cfpf_skiapathfont.cpp index 44e19bc8e5..27f4fde988 100644 --- a/core/fxge/android/cfpf_skiapathfont.cpp +++ b/core/fxge/android/cfpf_skiapathfont.cpp @@ -20,7 +20,7 @@ int32_t CFPF_SkiaPathFont::GetType() const { void CFPF_SkiaPathFont::SetPath(const char* pPath) { FX_Free(m_pPath); - int32_t iSize = FXSYS_strlen(pPath); + int32_t iSize = strlen(pPath); m_pPath = FX_Alloc(char, iSize + 1); memcpy(m_pPath, pPath, iSize * sizeof(char)); m_pPath[iSize] = 0; -- cgit v1.2.3