diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp | 2 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_pagelabel.cpp | 4 | ||||
-rw-r--r-- | core/fxcrt/cfx_bytestring.cpp | 37 | ||||
-rw-r--r-- | core/fxcrt/cfx_decimal.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/cfx_seekablestreamproxy.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/cfx_string_c_template.h | 2 | ||||
-rw-r--r-- | core/fxcrt/cfx_widestring.cpp | 36 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_buffer.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_utf.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/fx_stream.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/fxcrt_posix.cpp | 4 | ||||
-rw-r--r-- | core/fxcrt/fxcrt_windows.cpp | 9 | ||||
-rw-r--r-- | core/fxge/android/cfpf_skiafontmgr.cpp | 4 | ||||
-rw-r--r-- | core/fxge/win32/cpsoutput.cpp | 2 |
14 files changed, 62 insertions, 48 deletions
diff --git a/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp index 5f56b948cd..f1c84853dc 100644 --- a/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp @@ -54,7 +54,7 @@ TEST(SimpleParserTest, GetWord) { CFX_ByteStringC word = parser.GetWord(); EXPECT_EQ(std::string(reinterpret_cast<const char*>(data.expected), data.expected_size), - std::string(word.c_str(), word.GetLength())) + std::string(word.unterminated_c_str(), word.GetLength())) << " for case " << i; } } diff --git a/core/fpdfdoc/cpdf_pagelabel.cpp b/core/fpdfdoc/cpdf_pagelabel.cpp index 3892abad5e..41cbb8974e 100644 --- a/core/fpdfdoc/cpdf_pagelabel.cpp +++ b/core/fpdfdoc/cpdf_pagelabel.cpp @@ -142,5 +142,7 @@ int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const { } int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { - return GetPageByLabel(PDF_EncodeText(wsLabel.c_str()).AsStringC()); + // TODO(tsepez): check usage of c_str() below. + return GetPageByLabel( + PDF_EncodeText(wsLabel.unterminated_c_str()).AsStringC()); } diff --git a/core/fxcrt/cfx_bytestring.cpp b/core/fxcrt/cfx_bytestring.cpp index 9d67ed30a1..c88ad51ab3 100644 --- a/core/fxcrt/cfx_bytestring.cpp +++ b/core/fxcrt/cfx_bytestring.cpp @@ -101,15 +101,16 @@ CFX_ByteString GetByteString(uint16_t codepage, const CFX_WideStringC& wstr) { ASSERT(IsValidCodePage(codepage)); int src_len = wstr.GetLength(); - int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, - nullptr, 0, nullptr, nullptr); + int dest_len = + FXSYS_WideCharToMultiByte(codepage, 0, wstr.unterminated_c_str(), src_len, + nullptr, 0, nullptr, nullptr); if (!dest_len) return CFX_ByteString(); CFX_ByteString bstr; char* dest_buf = bstr.GetBuffer(dest_len); - FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, dest_buf, - dest_len, nullptr, nullptr); + FXSYS_WideCharToMultiByte(codepage, 0, wstr.unterminated_c_str(), src_len, + dest_buf, dest_len, nullptr, nullptr); bstr.ReleaseBuffer(dest_len); return bstr; } @@ -153,7 +154,8 @@ CFX_ByteString::CFX_ByteString(const char* ptr) CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& stringSrc) { if (!stringSrc.IsEmpty()) - m_pData.Reset(StringData::Create(stringSrc.c_str(), stringSrc.GetLength())); + m_pData.Reset(StringData::Create(stringSrc.unterminated_c_str(), + stringSrc.GetLength())); } CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& str1, @@ -166,8 +168,9 @@ CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& str1, return; m_pData.Reset(StringData::Create(nNewLen)); - m_pData->CopyContents(str1.c_str(), str1.GetLength()); - m_pData->CopyContentsAt(str1.GetLength(), str2.c_str(), str2.GetLength()); + m_pData->CopyContents(str1.unterminated_c_str(), str1.GetLength()); + m_pData->CopyContentsAt(str1.GetLength(), str2.unterminated_c_str(), + str2.GetLength()); } CFX_ByteString::CFX_ByteString( @@ -184,7 +187,8 @@ CFX_ByteString::CFX_ByteString( FX_STRSIZE nOffset = 0; for (const auto& item : list) { - m_pData->CopyContentsAt(nOffset, item.c_str(), item.GetLength()); + m_pData->CopyContentsAt(nOffset, item.unterminated_c_str(), + item.GetLength()); nOffset += item.GetLength(); } } @@ -209,7 +213,7 @@ const CFX_ByteString& CFX_ByteString::operator=( if (stringSrc.IsEmpty()) clear(); else - AssignCopy(stringSrc.c_str(), stringSrc.GetLength()); + AssignCopy(stringSrc.unterminated_c_str(), stringSrc.GetLength()); return *this; } @@ -243,7 +247,7 @@ const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteString& str) { const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteStringC& str) { if (!str.IsEmpty()) - Concat(str.c_str(), str.GetLength()); + Concat(str.unterminated_c_str(), str.GetLength()); return *this; } @@ -264,7 +268,8 @@ bool CFX_ByteString::operator==(const CFX_ByteStringC& str) const { return str.IsEmpty(); return m_pData->m_nDataLength == str.GetLength() && - memcmp(m_pData->m_String, str.c_str(), str.GetLength()) == 0; + memcmp(m_pData->m_String, str.unterminated_c_str(), str.GetLength()) == + 0; } bool CFX_ByteString::operator==(const CFX_ByteString& other) const { @@ -594,7 +599,7 @@ FX_STRSIZE CFX_ByteString::Find(const CFX_ByteStringC& pSub, const char* pStr = FX_strstr(m_pData->m_String + nStart, m_pData->m_nDataLength - nStart, - pSub.c_str(), pSub.GetLength()); + pSub.unterminated_c_str(), pSub.GetLength()); return pStr ? (int)(pStr - m_pData->m_String) : -1; } @@ -660,7 +665,7 @@ FX_STRSIZE CFX_ByteString::Replace(const CFX_ByteStringC& pOld, char* pEnd = m_pData->m_String + m_pData->m_nDataLength; while (1) { const char* pTarget = FX_strstr(pStart, (FX_STRSIZE)(pEnd - pStart), - pOld.c_str(), nSourceLen); + pOld.unterminated_c_str(), nSourceLen); if (!pTarget) break; @@ -683,10 +688,10 @@ FX_STRSIZE CFX_ByteString::Replace(const CFX_ByteStringC& pOld, char* pDest = pNewData->m_String; for (FX_STRSIZE i = 0; i < nCount; i++) { const char* pTarget = FX_strstr(pStart, (FX_STRSIZE)(pEnd - pStart), - pOld.c_str(), nSourceLen); + pOld.unterminated_c_str(), nSourceLen); memcpy(pDest, pStart, pTarget - pStart); pDest += pTarget - pStart; - memcpy(pDest, pNew.c_str(), pNew.GetLength()); + memcpy(pDest, pNew.unterminated_c_str(), pNew.GetLength()); pDest += pNew.GetLength(); pStart = pTarget + nSourceLen; } @@ -879,5 +884,5 @@ std::ostream& operator<<(std::ostream& os, const CFX_ByteString& str) { } std::ostream& operator<<(std::ostream& os, const CFX_ByteStringC& str) { - return os.write(str.c_str(), str.GetLength()); + return os.write(str.unterminated_c_str(), str.GetLength()); } diff --git a/core/fxcrt/cfx_decimal.cpp b/core/fxcrt/cfx_decimal.cpp index a463305f6a..b900e069a7 100644 --- a/core/fxcrt/cfx_decimal.cpp +++ b/core/fxcrt/cfx_decimal.cpp @@ -295,7 +295,7 @@ CFX_Decimal::CFX_Decimal(float val, uint8_t scale) { } CFX_Decimal::CFX_Decimal(const CFX_WideStringC& strObj) { - const wchar_t* str = strObj.c_str(); + const wchar_t* str = strObj.unterminated_c_str(); const wchar_t* strBound = str + strObj.GetLength(); bool pointmet = false; bool negmet = false; diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp index 37dbed1fca..8cf855217a 100644 --- a/core/fxcrt/cfx_seekablestreamproxy.cpp +++ b/core/fxcrt/cfx_seekablestreamproxy.cpp @@ -294,7 +294,7 @@ void CFX_SeekableStreamProxy::WriteString(const CFX_WideStringC& str) { m_wCodePage != FX_CODEPAGE_UTF8) { return; } - if (!m_pStream->WriteBlock(str.c_str(), m_iPosition, + if (!m_pStream->WriteBlock(str.unterminated_c_str(), m_iPosition, str.GetLength() * sizeof(wchar_t))) { return; } diff --git a/core/fxcrt/cfx_string_c_template.h b/core/fxcrt/cfx_string_c_template.h index 5dfff69a95..1473160334 100644 --- a/core/fxcrt/cfx_string_c_template.h +++ b/core/fxcrt/cfx_string_c_template.h @@ -112,7 +112,7 @@ class CFX_StringCTemplate { } const UnsignedType* raw_str() const { return m_Ptr.Get(); } - const CharType* c_str() const { + const CharType* unterminated_c_str() const { return reinterpret_cast<const CharType*>(m_Ptr.Get()); } diff --git a/core/fxcrt/cfx_widestring.cpp b/core/fxcrt/cfx_widestring.cpp index 70a0cb63be..6a4fbb9846 100644 --- a/core/fxcrt/cfx_widestring.cpp +++ b/core/fxcrt/cfx_widestring.cpp @@ -263,15 +263,15 @@ CFX_WideString GetWideString(uint16_t codepage, const CFX_ByteStringC& bstr) { ASSERT(IsValidCodePage(codepage)); int src_len = bstr.GetLength(); - int dest_len = - FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0); + int dest_len = FXSYS_MultiByteToWideChar( + codepage, 0, bstr.unterminated_c_str(), src_len, nullptr, 0); if (!dest_len) return CFX_WideString(); CFX_WideString wstr; wchar_t* dest_buf = wstr.GetBuffer(dest_len); - FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf, - dest_len); + FXSYS_MultiByteToWideChar(codepage, 0, bstr.unterminated_c_str(), src_len, + dest_buf, dest_len); wstr.ReleaseBuffer(dest_len); return wstr; } @@ -308,7 +308,8 @@ CFX_WideString::CFX_WideString(const wchar_t* ptr) CFX_WideString::CFX_WideString(const CFX_WideStringC& stringSrc) { if (!stringSrc.IsEmpty()) { - m_pData.Reset(StringData::Create(stringSrc.c_str(), stringSrc.GetLength())); + m_pData.Reset(StringData::Create(stringSrc.unterminated_c_str(), + stringSrc.GetLength())); } } @@ -322,8 +323,9 @@ CFX_WideString::CFX_WideString(const CFX_WideStringC& str1, return; m_pData.Reset(StringData::Create(nNewLen)); - m_pData->CopyContents(str1.c_str(), str1.GetLength()); - m_pData->CopyContentsAt(str1.GetLength(), str2.c_str(), str2.GetLength()); + m_pData->CopyContents(str1.unterminated_c_str(), str1.GetLength()); + m_pData->CopyContentsAt(str1.GetLength(), str2.unterminated_c_str(), + str2.GetLength()); } CFX_WideString::CFX_WideString( @@ -340,7 +342,8 @@ CFX_WideString::CFX_WideString( FX_STRSIZE nOffset = 0; for (const auto& item : list) { - m_pData->CopyContentsAt(nOffset, item.c_str(), item.GetLength()); + m_pData->CopyContentsAt(nOffset, item.unterminated_c_str(), + item.GetLength()); nOffset += item.GetLength(); } } @@ -361,7 +364,7 @@ const CFX_WideString& CFX_WideString::operator=( if (stringSrc.IsEmpty()) clear(); else - AssignCopy(stringSrc.c_str(), stringSrc.GetLength()); + AssignCopy(stringSrc.unterminated_c_str(), stringSrc.GetLength()); return *this; } @@ -395,7 +398,7 @@ const CFX_WideString& CFX_WideString::operator+=(const CFX_WideString& str) { const CFX_WideString& CFX_WideString::operator+=(const CFX_WideStringC& str) { if (!str.IsEmpty()) - Concat(str.c_str(), str.GetLength()); + Concat(str.unterminated_c_str(), str.GetLength()); return *this; } @@ -416,7 +419,8 @@ bool CFX_WideString::operator==(const CFX_WideStringC& str) const { return str.IsEmpty(); return m_pData->m_nDataLength == str.GetLength() && - wmemcmp(m_pData->m_String, str.c_str(), str.GetLength()) == 0; + wmemcmp(m_pData->m_String, str.unterminated_c_str(), + str.GetLength()) == 0; } bool CFX_WideString::operator==(const CFX_WideString& other) const { @@ -746,7 +750,7 @@ FX_STRSIZE CFX_WideString::Find(const CFX_WideStringC& pSub, const wchar_t* pStr = FX_wcsstr(m_pData->m_String + nStart, m_pData->m_nDataLength - nStart, - pSub.c_str(), pSub.GetLength()); + pSub.unterminated_c_str(), pSub.GetLength()); return pStr ? (int)(pStr - m_pData->m_String) : -1; } @@ -812,7 +816,7 @@ FX_STRSIZE CFX_WideString::Replace(const CFX_WideStringC& pOld, 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.c_str(), nSourceLen); + pOld.unterminated_c_str(), nSourceLen); if (!pTarget) break; @@ -835,10 +839,10 @@ FX_STRSIZE CFX_WideString::Replace(const CFX_WideStringC& pOld, wchar_t* pDest = pNewData->m_String; for (FX_STRSIZE i = 0; i < nCount; i++) { const wchar_t* pTarget = FX_wcsstr(pStart, (FX_STRSIZE)(pEnd - pStart), - pOld.c_str(), nSourceLen); + pOld.unterminated_c_str(), nSourceLen); wmemcpy(pDest, pStart, pTarget - pStart); pDest += pTarget - pStart; - wmemcpy(pDest, pNew.c_str(), pNew.GetLength()); + wmemcpy(pDest, pNew.unterminated_c_str(), pNew.GetLength()); pDest += pNew.GetLength(); pStart = pTarget + nSourceLen; } @@ -1060,7 +1064,7 @@ std::ostream& operator<<(std::ostream& os, const CFX_WideString& str) { } std::wostream& operator<<(std::wostream& os, const CFX_WideStringC& str) { - return os.write(str.c_str(), str.GetLength()); + return os.write(str.unterminated_c_str(), str.GetLength()); } std::ostream& operator<<(std::ostream& os, const CFX_WideStringC& str) { diff --git a/core/fxcrt/fx_basic_buffer.cpp b/core/fxcrt/fx_basic_buffer.cpp index 36da3f4053..bcf0570d32 100644 --- a/core/fxcrt/fx_basic_buffer.cpp +++ b/core/fxcrt/fx_basic_buffer.cpp @@ -133,7 +133,7 @@ void CFX_WideTextBuf::AppendChar(wchar_t ch) { } CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideStringC& str) { - AppendBlock(str.c_str(), str.GetLength() * sizeof(wchar_t)); + AppendBlock(str.unterminated_c_str(), str.GetLength() * sizeof(wchar_t)); return *this; } diff --git a/core/fxcrt/fx_basic_utf.cpp b/core/fxcrt/fx_basic_utf.cpp index 10aa918962..4dbfa37284 100644 --- a/core/fxcrt/fx_basic_utf.cpp +++ b/core/fxcrt/fx_basic_utf.cpp @@ -76,7 +76,7 @@ void CFX_UTF8Encoder::Input(wchar_t unicode) { CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) { FX_STRSIZE len = wsStr.GetLength(); - const wchar_t* pStr = wsStr.c_str(); + const wchar_t* pStr = wsStr.unterminated_c_str(); CFX_UTF8Encoder encoder; while (len-- > 0) encoder.Input(*pStr++); diff --git a/core/fxcrt/fx_stream.cpp b/core/fxcrt/fx_stream.cpp index ba21461098..a64b239546 100644 --- a/core/fxcrt/fx_stream.cpp +++ b/core/fxcrt/fx_stream.cpp @@ -95,5 +95,5 @@ bool IFX_SeekableStream::WriteBlock(const void* buffer, size_t size) { } bool IFX_SeekableStream::WriteString(const CFX_ByteStringC& str) { - return WriteBlock(str.c_str(), str.GetLength()); + return WriteBlock(str.unterminated_c_str(), str.GetLength()); } diff --git a/core/fxcrt/fxcrt_posix.cpp b/core/fxcrt/fxcrt_posix.cpp index ca4ac161a4..4d867dd688 100644 --- a/core/fxcrt/fxcrt_posix.cpp +++ b/core/fxcrt/fxcrt_posix.cpp @@ -56,7 +56,9 @@ bool CFXCRT_FileAccess_Posix::Open(const CFX_ByteStringC& fileName, int32_t nFlags; int32_t nMasks; FXCRT_Posix_GetFileMode(dwMode, nFlags, nMasks); - m_nFD = open(fileName.c_str(), nFlags, nMasks); + + // TODO(tsepez): check usage of c_str() below. + m_nFD = open(fileName.unterminated_c_str(), nFlags, nMasks); return m_nFD > -1; } diff --git a/core/fxcrt/fxcrt_windows.cpp b/core/fxcrt/fxcrt_windows.cpp index 6230c74eb7..1a2a36735e 100644 --- a/core/fxcrt/fxcrt_windows.cpp +++ b/core/fxcrt/fxcrt_windows.cpp @@ -57,8 +57,8 @@ bool CFXCRT_FileAccess_Win64::Open(const CFX_ByteStringC& fileName, uint32_t dwAccess, dwShare, dwCreation; FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation); - m_hFile = ::CreateFileA(fileName.c_str(), dwAccess, dwShare, nullptr, - dwCreation, FILE_ATTRIBUTE_NORMAL, nullptr); + m_hFile = ::CreateFileA(fileName.unterminated_c_str(), dwAccess, dwShare, + nullptr, dwCreation, FILE_ATTRIBUTE_NORMAL, nullptr); if (m_hFile == INVALID_HANDLE_VALUE) m_hFile = nullptr; @@ -72,8 +72,9 @@ bool CFXCRT_FileAccess_Win64::Open(const CFX_WideStringC& fileName, uint32_t dwAccess, dwShare, dwCreation; FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation); - m_hFile = ::CreateFileW((LPCWSTR)fileName.c_str(), dwAccess, dwShare, nullptr, - dwCreation, FILE_ATTRIBUTE_NORMAL, nullptr); + m_hFile = + ::CreateFileW((LPCWSTR)fileName.unterminated_c_str(), dwAccess, dwShare, + nullptr, dwCreation, FILE_ATTRIBUTE_NORMAL, nullptr); if (m_hFile == INVALID_HANDLE_VALUE) m_hFile = nullptr; diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp index ec5c610150..23fcd5bbec 100644 --- a/core/fxge/android/cfpf_skiafontmgr.cpp +++ b/core/fxge/android/cfpf_skiafontmgr.cpp @@ -161,7 +161,7 @@ uint32_t FPF_SkiaGetCharset(uint8_t uCharset) { uint32_t FPF_SKIANormalizeFontName(const CFX_ByteStringC& bsfamily) { uint32_t dwHash = 0; int32_t iLength = bsfamily.GetLength(); - const char* pBuffer = bsfamily.c_str(); + const char* pBuffer = bsfamily.unterminated_c_str(); for (int32_t i = 0; i < iLength; i++) { char ch = pBuffer[i]; if (ch == ' ' || ch == '-' || ch == ',') @@ -395,7 +395,7 @@ FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const CFX_ByteStringC& bsFile, return nullptr; FXFT_Open_Args args; args.flags = FT_OPEN_PATHNAME; - args.pathname = const_cast<FT_String*>(bsFile.c_str()); + args.pathname = const_cast<FT_String*>(bsFile.unterminated_c_str()); FXFT_Face face; if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) return nullptr; diff --git a/core/fxge/win32/cpsoutput.cpp b/core/fxge/win32/cpsoutput.cpp index 7139340a6e..1af6dbdced 100644 --- a/core/fxge/win32/cpsoutput.cpp +++ b/core/fxge/win32/cpsoutput.cpp @@ -32,5 +32,5 @@ bool CPSOutput::WriteBlock(const void* str, size_t len) { } bool CPSOutput::WriteString(const CFX_ByteStringC& str) { - return WriteBlock(str.c_str(), str.GetLength()); + return WriteBlock(str.unterminated_c_str(), str.GetLength()); } |