diff options
31 files changed, 111 insertions, 97 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()); } diff --git a/fpdfsdk/fsdk_filewriteadapter.cpp b/fpdfsdk/fsdk_filewriteadapter.cpp index ff527a6f2e..50394c3286 100644 --- a/fpdfsdk/fsdk_filewriteadapter.cpp +++ b/fpdfsdk/fsdk_filewriteadapter.cpp @@ -18,5 +18,5 @@ bool FSDK_FileWriteAdapter::WriteBlock(const void* data, size_t size) { } bool FSDK_FileWriteAdapter::WriteString(const CFX_ByteStringC& str) { - return WriteBlock(str.c_str(), str.GetLength()); + return WriteBlock(str.unterminated_c_str(), str.GetLength()); } diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index cb8f69f9da..515bdcb65f 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -218,19 +218,16 @@ CFX_WideString ChangeObjName(const CFX_WideString& str) { sRet.Replace(L"_", L"."); return sRet; } + bool CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name, CFXJSE_Value* pValue) { - const char* name = utf8Name.c_str(); - v8::Isolate::Scope isolate_scope(GetIsolate()); v8::HandleScope handle_scope(GetIsolate()); v8::Local<v8::Context> context = NewLocalContext(); v8::Context::Scope context_scope(context); - - v8::Local<v8::Value> propvalue = - context->Global()->Get(v8::String::NewFromUtf8( - GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength())); - + v8::Local<v8::Value> propvalue = context->Global()->Get( + v8::String::NewFromUtf8(GetIsolate(), utf8Name.unterminated_c_str(), + v8::String::kNormalString, utf8Name.GetLength())); if (propvalue.IsEmpty()) { pValue->SetUndefined(); return false; @@ -238,24 +235,22 @@ bool CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name, pValue->ForceSetValue(propvalue); return true; } + bool CJS_Runtime::SetValueByName(const CFX_ByteStringC& utf8Name, CFXJSE_Value* pValue) { if (utf8Name.IsEmpty() || !pValue) return false; - const char* name = utf8Name.c_str(); + v8::Isolate* pIsolate = GetIsolate(); v8::Isolate::Scope isolate_scope(pIsolate); v8::HandleScope handle_scope(pIsolate); v8::Local<v8::Context> context = NewLocalContext(); v8::Context::Scope context_scope(context); - - // v8::Local<v8::Context> tmpCotext = - // v8::Local<v8::Context>::New(GetIsolate(), m_context); v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue()); context->Global()->Set( - v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, - utf8Name.GetLength()), + v8::String::NewFromUtf8(pIsolate, utf8Name.unterminated_c_str(), + v8::String::kNormalString, utf8Name.GetLength()), propvalue); return true; } diff --git a/fxjs/cfxjse_value.cpp b/fxjs/cfxjse_value.cpp index fb7fe20e21..c2eaa408a4 100644 --- a/fxjs/cfxjse_value.cpp +++ b/fxjs/cfxjse_value.cpp @@ -58,7 +58,7 @@ void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Message) { CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); v8::Local<v8::String> hMessage = v8::String::NewFromUtf8( - pIsolate, utf8Message.c_str(), v8::String::kNormalString, + pIsolate, utf8Message.unterminated_c_str(), v8::String::kNormalString, utf8Message.GetLength()); v8::Local<v8::Value> hError = v8::Exception::Error(hMessage); pIsolate->ThrowException(hError); @@ -138,7 +138,7 @@ bool CFXJSE_Value::SetObjectProperty(const CFX_ByteStringC& szPropName, v8::Local<v8::Value> hPropValue = v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->DirectGetValue()); return (bool)hObject.As<v8::Object>()->Set( - v8::String::NewFromUtf8(m_pIsolate, szPropName.c_str(), + v8::String::NewFromUtf8(m_pIsolate, szPropName.unterminated_c_str(), v8::String::kNormalString, szPropName.GetLength()), hPropValue); @@ -155,8 +155,8 @@ bool CFXJSE_Value::GetObjectProperty(const CFX_ByteStringC& szPropName, v8::Local<v8::Value> hPropValue = hObject.As<v8::Object>()->Get(v8::String::NewFromUtf8( - m_pIsolate, szPropName.c_str(), v8::String::kNormalString, - szPropName.GetLength())); + m_pIsolate, szPropName.unterminated_c_str(), + v8::String::kNormalString, szPropName.GetLength())); lpPropValue->ForceSetValue(hPropValue); return true; } @@ -195,7 +195,7 @@ bool CFXJSE_Value::DeleteObjectProperty(const CFX_ByteStringC& szPropName) { return false; hObject.As<v8::Object>()->Delete(v8::String::NewFromUtf8( - m_pIsolate, szPropName.c_str(), v8::String::kNormalString, + m_pIsolate, szPropName.unterminated_c_str(), v8::String::kNormalString, szPropName.GetLength())); return true; } @@ -209,7 +209,7 @@ bool CFXJSE_Value::HasObjectOwnProperty(const CFX_ByteStringC& szPropName, return false; v8::Local<v8::String> hKey = v8::String::NewFromUtf8( - m_pIsolate, szPropName.c_str(), v8::String::kNormalString, + m_pIsolate, szPropName.unterminated_c_str(), v8::String::kNormalString, szPropName.GetLength()); return hObject.As<v8::Object>()->HasRealNamedProperty(hKey) || (bUseTypeGetter && @@ -232,7 +232,7 @@ bool CFXJSE_Value::SetObjectOwnProperty(const CFX_ByteStringC& szPropName, return hObject.As<v8::Object>() ->DefineOwnProperty( m_pIsolate->GetCurrentContext(), - v8::String::NewFromUtf8(m_pIsolate, szPropName.c_str(), + v8::String::NewFromUtf8(m_pIsolate, szPropName.unterminated_c_str(), v8::String::kNormalString, szPropName.GetLength()), pValue) diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp index 970e4f144d..d3d2010b30 100644 --- a/fxjs/fxjs_v8.cpp +++ b/fxjs/fxjs_v8.cpp @@ -648,7 +648,7 @@ v8::Local<v8::Boolean> CFXJS_Engine::NewBoolean(bool b) { v8::Local<v8::String> CFXJS_Engine::NewString(const CFX_ByteStringC& str) { v8::Isolate* pIsolate = m_isolate ? m_isolate : v8::Isolate::GetCurrent(); - return v8::String::NewFromUtf8(pIsolate, str.c_str(), + return v8::String::NewFromUtf8(pIsolate, str.unterminated_c_str(), v8::NewStringType::kNormal, str.GetLength()) .ToLocalChecked(); } diff --git a/testing/xfa_js_embedder_test.cpp b/testing/xfa_js_embedder_test.cpp index e5a30f6b88..d36cc815e6 100644 --- a/testing/xfa_js_embedder_test.cpp +++ b/testing/xfa_js_embedder_test.cpp @@ -59,7 +59,7 @@ bool XFAJSEmbedderTest::Execute(const CFX_ByteStringC& input) { CFXJSE_Value msg(GetIsolate()); value_->GetObjectPropertyByIdx(1, &msg); - fprintf(stderr, "JS: %.*s\n", input.GetLength(), input.c_str()); + fprintf(stderr, "JS: %.*s\n", input.GetLength(), input.unterminated_c_str()); // If the parsing of the input fails, then v8 will not run, so there will be // no value here to print. if (msg.IsString() && !msg.ToWideString().IsEmpty()) diff --git a/xfa/fde/css/cfde_cssdeclaration.cpp b/xfa/fde/css/cfde_cssdeclaration.cpp index 00a2c9e33c..e15e5f7fe7 100644 --- a/xfa/fde/css/cfde_cssdeclaration.cpp +++ b/xfa/fde/css/cfde_cssdeclaration.cpp @@ -160,9 +160,8 @@ void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyTable* pTable, const CFX_WideStringC& value) { ASSERT(!value.IsEmpty()); - const wchar_t* pszValue = value.c_str(); + const wchar_t* pszValue = value.unterminated_c_str(); int32_t iValueLen = value.GetLength(); - bool bImportant = false; if (iValueLen >= 10 && pszValue[iValueLen - 10] == '!' && FXSYS_wcsnicmp(L"important", pszValue + iValueLen - 9, 9) == 0) { diff --git a/xfa/fde/css/cfde_cssselector.cpp b/xfa/fde/css/cfde_cssselector.cpp index c1e9f7f22a..ad2ec40c2b 100644 --- a/xfa/fde/css/cfde_cssselector.cpp +++ b/xfa/fde/css/cfde_cssselector.cpp @@ -52,7 +52,7 @@ std::unique_ptr<CFDE_CSSSelector> CFDE_CSSSelector::FromString( const CFX_WideStringC& str) { ASSERT(!str.IsEmpty()); - const wchar_t* psz = str.c_str(); + const wchar_t* psz = str.unterminated_c_str(); const wchar_t* pStart = psz; const wchar_t* pEnd = psz + str.GetLength(); for (; psz < pEnd; ++psz) { diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp index a9e5f7c795..0abc86fbf3 100644 --- a/xfa/fgas/crt/cfgas_formatstring.cpp +++ b/xfa/fgas/crt/cfgas_formatstring.cpp @@ -769,7 +769,7 @@ bool FX_TimeFromCanonical(const CFX_WideStringC& wsTime, if (wsTime.GetLength() == 0) return false; - const wchar_t* str = wsTime.c_str(); + const wchar_t* str = wsTime.unterminated_c_str(); int len = wsTime.GetLength(); int cc = 0; diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp index 90a144fcc1..e863a0e0d3 100644 --- a/xfa/fwl/theme/cfwl_widgettp.cpp +++ b/xfa/fwl/theme/cfwl_widgettp.cpp @@ -291,8 +291,9 @@ bool CFWL_FontData::LoadFont(const CFX_WideStringC& wsFontFamily, m_pFontMgr = CFGAS_FontMgr::Create(m_pFontSource.get()); #endif } - m_pFont = CFGAS_GEFont::LoadFont(wsFontFamily.c_str(), dwFontStyles, - dwCodePage, m_pFontMgr.get()); + // TODO(tsepez): check usage of c_str() below. + m_pFont = CFGAS_GEFont::LoadFont(wsFontFamily.unterminated_c_str(), + dwFontStyles, dwCodePage, m_pFontMgr.get()); return !!m_pFont; } diff --git a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp index 8c94444075..5f1a4d2989 100644 --- a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp @@ -1970,8 +1970,8 @@ int32_t CXFA_FM2JSContext::DateString2Num(const CFX_ByteStringC& szDateString) { int32_t iDay = 0; if (iLength <= 10) { int32_t iStyle = -1; - if (!IsIsoDateFormat(szDateString.c_str(), iLength, iStyle, iYear, iMonth, - iDay)) { + if (!IsIsoDateFormat(szDateString.unterminated_c_str(), iLength, iStyle, + iYear, iMonth, iDay)) { return 0; } } else { @@ -1981,9 +1981,9 @@ int32_t CXFA_FM2JSContext::DateString2Num(const CFX_ByteStringC& szDateString) { int32_t iMilliSecond = 0; int32_t iZoneHour = 0; int32_t iZoneMinute = 0; - if (!IsIsoDateTimeFormat(szDateString.c_str(), iLength, iYear, iMonth, iDay, - iHour, iMinute, iSecond, iMilliSecond, iZoneHour, - iZoneMinute)) { + if (!IsIsoDateTimeFormat(szDateString.unterminated_c_str(), iLength, iYear, + iMonth, iDay, iHour, iMinute, iSecond, + iMilliSecond, iZoneHour, iZoneMinute)) { return 0; } } @@ -3516,7 +3516,8 @@ void CXFA_FM2JSContext::EncodeURL(const CFX_ByteStringC& szURLString, // static void CXFA_FM2JSContext::EncodeHTML(const CFX_ByteStringC& szHTMLString, CFX_ByteTextBuf& szResultBuf) { - CFX_ByteString str = szHTMLString.c_str(); + // TODO(tsepez): check usage of c_str() below. + CFX_ByteString str = szHTMLString.unterminated_c_str(); CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(str.AsStringC()); const wchar_t* strCode = L"0123456789abcdef"; wchar_t strEncode[9]; @@ -3637,13 +3638,14 @@ bool CXFA_FM2JSContext::HTMLSTR2Code(const CFX_WideStringC& pData, uint32_t* iCode) { auto cmpFunc = [](const XFA_FMHtmlReserveCode& iter, const CFX_WideStringC& val) { - return wcscmp(val.c_str(), iter.m_htmlReserve) > 0; + // TODO(tsepez): check usage of c_str() below. + return wcscmp(val.unterminated_c_str(), iter.m_htmlReserve) > 0; }; const XFA_FMHtmlReserveCode* result = std::lower_bound(std::begin(reservesForDecode), std::end(reservesForDecode), pData, cmpFunc); if (result != std::end(reservesForEncode) && - !wcscmp(pData.c_str(), result->m_htmlReserve)) { + !wcscmp(pData.unterminated_c_str(), result->m_htmlReserve)) { *iCode = result->m_uCode; return true; } @@ -4424,7 +4426,7 @@ void CXFA_FM2JSContext::TrillionUS(const CFX_ByteStringC& szData, "Sixty", "Seventy", "Eighty", "Ninety"}; CFX_ByteStringC pComm[] = {" Hundred ", " Thousand ", " Million ", " Billion ", "Trillion"}; - const char* pData = szData.c_str(); + const char* pData = szData.unterminated_c_str(); int32_t iLength = szData.GetLength(); int32_t iComm = 0; if (iLength > 12) @@ -4513,7 +4515,7 @@ void CXFA_FM2JSContext::TrillionUS(const CFX_ByteStringC& szData, void CXFA_FM2JSContext::WordUS(const CFX_ByteStringC& szData, int32_t iStyle, CFX_ByteTextBuf& strBuf) { - const char* pData = szData.c_str(); + const char* pData = szData.unterminated_c_str(); int32_t iLength = szData.GetLength(); if (iStyle < 0 || iStyle > 2) { return; @@ -6094,7 +6096,9 @@ void CXFA_FM2JSContext::GlobalPropertyGetter(CFXJSE_Value* pValue) { void CXFA_FM2JSContext::ThrowNoDefaultPropertyException( const CFX_ByteStringC& name) const { - ThrowException(L"%.16S doesn't have a default property.", name.c_str()); + // TODO(tsepez): check usage of c_str() below. + ThrowException(L"%.16S doesn't have a default property.", + name.unterminated_c_str()); } void CXFA_FM2JSContext::ThrowCompilerErrorException() const { diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp index 908cd2f04a..6b8508a503 100644 --- a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp @@ -111,7 +111,7 @@ CXFA_FMToken::CXFA_FMToken(uint32_t uLineNum) CXFA_FMToken::~CXFA_FMToken() {} CXFA_FMLexer::CXFA_FMLexer(const CFX_WideStringC& wsFormCalc) - : m_ptr(wsFormCalc.c_str()), + : m_ptr(wsFormCalc.unterminated_c_str()), m_end(m_ptr + wsFormCalc.GetLength() - 1), m_uCurrentLine(1), m_LexerError(false) {} diff --git a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp index b229b23151..d9eb5d699f 100644 --- a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp @@ -325,7 +325,7 @@ static int32_t XFA_FilterName(const CFX_WideStringC& wsExpression, } wchar_t* pBuf = wsFilter.GetBuffer(iLength - nStart); int32_t nCount = 0; - const wchar_t* pSrc = wsExpression.c_str(); + const wchar_t* pSrc = wsExpression.unterminated_c_str(); wchar_t wCur; while (nStart < iLength) { wCur = pSrc[nStart++]; diff --git a/xfa/fxfa/parser/cxfa_data.cpp b/xfa/fxfa/parser/cxfa_data.cpp index bdfc25c79c..7bf18a5d3e 100644 --- a/xfa/fxfa/parser/cxfa_data.cpp +++ b/xfa/fxfa/parser/cxfa_data.cpp @@ -17,7 +17,7 @@ FX_ARGB CXFA_Data::ToColor(const CFX_WideStringC& wsValue) { return 0xff000000; int cc = 0; - const wchar_t* str = wsValue.c_str(); + const wchar_t* str = wsValue.unterminated_c_str(); int len = wsValue.GetLength(); while (FXSYS_iswspace(str[cc]) && cc < len) cc++; diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp index b6e6e7f8e9..694b24dc27 100644 --- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp @@ -1748,7 +1748,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { : containerSize.width - fLeftInset - fRightInset; CFX_WideStringC wsColumnWidths; if (pLayoutNode->TryCData(XFA_ATTRIBUTE_ColumnWidths, wsColumnWidths)) { - auto widths = SeparateStringW(wsColumnWidths.c_str(), + auto widths = SeparateStringW(wsColumnWidths.unterminated_c_str(), wsColumnWidths.GetLength(), L' '); for (auto& width : widths) { width.TrimLeft(L' '); diff --git a/xfa/fxfa/parser/cxfa_measurement.cpp b/xfa/fxfa/parser/cxfa_measurement.cpp index 9173223d3c..70420d7b5e 100644 --- a/xfa/fxfa/parser/cxfa_measurement.cpp +++ b/xfa/fxfa/parser/cxfa_measurement.cpp @@ -28,7 +28,7 @@ void CXFA_Measurement::Set(const CFX_WideStringC& wsMeasure) { } int32_t iUsedLen = 0; int32_t iOffset = (wsMeasure.GetAt(0) == L'=') ? 1 : 0; - float fValue = FXSYS_wcstof(wsMeasure.c_str() + iOffset, + float fValue = FXSYS_wcstof(wsMeasure.unterminated_c_str() + iOffset, wsMeasure.GetLength() - iOffset, &iUsedLen); XFA_UNIT eUnit = GetUnit(wsMeasure.Mid(iOffset + iUsedLen)); Set(fValue, eUnit); diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 845d3f379d..5c4f8d102e 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -3591,7 +3591,7 @@ bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr, return SetBoolean(pAttr->eName, wsValue != L"0", bNotify); case XFA_ATTRIBUTETYPE_Integer: return SetInteger(pAttr->eName, - FXSYS_round(FXSYS_wcstof(wsValue.c_str(), + FXSYS_round(FXSYS_wcstof(wsValue.unterminated_c_str(), wsValue.GetLength(), nullptr)), bNotify); case XFA_ATTRIBUTETYPE_Measure: @@ -4554,7 +4554,8 @@ bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) { static_cast<CFX_XMLElement*>(pNode->m_pXMLNode); CFX_WideStringC wsAttributeName = pNode->GetCData(XFA_ATTRIBUTE_QualifiedName); - pXMLElement->RemoveAttribute(wsAttributeName.c_str()); + // TODO(tsepez): check usage of c_str() below. + pXMLElement->RemoveAttribute(wsAttributeName.unterminated_c_str()); } CFX_WideString wsName; pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); @@ -4850,7 +4851,7 @@ bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) { } void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) { - SetMapModuleBuffer(pKey, (void*)wsValue.c_str(), + SetMapModuleBuffer(pKey, (void*)wsValue.unterminated_c_str(), wsValue.GetLength() * sizeof(wchar_t)); } diff --git a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp index add8cb8fcb..93b2d86061 100644 --- a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp @@ -502,7 +502,7 @@ int32_t CXFA_ResolveProcessor::GetFilter(const CFX_WideStringC& wsExpression, int32_t nConditionCount = 0; std::vector<int32_t> stack; int32_t nType = -1; - const wchar_t* pSrc = wsExpression.c_str(); + const wchar_t* pSrc = wsExpression.unterminated_c_str(); wchar_t wPrev = 0, wCur; bool bIsCondition = false; while (nStart < iLength) { |