summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/font/cpdf_cmapparser_unittest.cpp8
-rw-r--r--core/fxcrt/cfx_binarybuf.cpp5
-rw-r--r--core/fxcrt/cfx_bytestring.cpp30
-rw-r--r--core/fxcrt/cfx_bytestring.h10
-rw-r--r--core/fxcrt/cfx_bytestring_unittest.cpp134
-rw-r--r--core/fxcrt/cfx_seekablestreamproxy.cpp5
-rw-r--r--core/fxcrt/cfx_string_c_template.h16
-rw-r--r--core/fxcrt/cfx_widestring.cpp37
-rw-r--r--core/fxcrt/cfx_widestring.h10
-rw-r--r--core/fxcrt/cfx_widestring_unittest.cpp110
-rw-r--r--core/fxcrt/fx_system.h7
-rw-r--r--fpdfsdk/fpdf_sysfontinfo.cpp2
-rw-r--r--fxbarcode/datamatrix/BC_ErrorCorrection.cpp3
-rw-r--r--fxbarcode/datamatrix/BC_HighLevelEncoder.cpp17
-rw-r--r--fxbarcode/qrcode/BC_QRCoderEncoder.cpp12
-rw-r--r--testing/xfa_js_embedder_test.cpp3
-rw-r--r--xfa/fgas/crt/cfgas_formatstring.cpp18
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_scriptcontext.cpp12
19 files changed, 212 insertions, 229 deletions
diff --git a/core/fpdfapi/font/cpdf_cmapparser_unittest.cpp b/core/fpdfapi/font/cpdf_cmapparser_unittest.cpp
index 0d55aa274d..8d99b0dbff 100644
--- a/core/fpdfapi/font/cpdf_cmapparser_unittest.cpp
+++ b/core/fpdfapi/font/cpdf_cmapparser_unittest.cpp
@@ -45,11 +45,11 @@ TEST(cpdf_cmapparser, CMap_GetCodeRange) {
// m_CharSize must be <= 4
EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "<aaaaaaaaaa>", ""));
- EXPECT_EQ(5, range.m_CharSize);
+ EXPECT_EQ(5u, range.m_CharSize);
EXPECT_TRUE(
CPDF_CMapParser::CMap_GetCodeRange(range, "<12345678>", "<87654321>"));
- EXPECT_EQ(4, range.m_CharSize);
+ EXPECT_EQ(4u, range.m_CharSize);
{
uint8_t lower[4] = {18, 52, 86, 120};
uint8_t upper[4] = {135, 101, 67, 33};
@@ -59,13 +59,13 @@ TEST(cpdf_cmapparser, CMap_GetCodeRange) {
// Hex characters
EXPECT_TRUE(CPDF_CMapParser::CMap_GetCodeRange(range, "<a1>", "<F3>"));
- EXPECT_EQ(1, range.m_CharSize);
+ EXPECT_EQ(1u, range.m_CharSize);
EXPECT_EQ(161, range.m_Lower[0]);
EXPECT_EQ(243, range.m_Upper[0]);
// The second string should return 0's if it is shorter
EXPECT_TRUE(CPDF_CMapParser::CMap_GetCodeRange(range, "<a1>", ""));
- EXPECT_EQ(1, range.m_CharSize);
+ EXPECT_EQ(1u, range.m_CharSize);
EXPECT_EQ(161, range.m_Lower[0]);
EXPECT_EQ(0, range.m_Upper[0]);
}
diff --git a/core/fxcrt/cfx_binarybuf.cpp b/core/fxcrt/cfx_binarybuf.cpp
index 6c67912d3b..73fe945fd6 100644
--- a/core/fxcrt/cfx_binarybuf.cpp
+++ b/core/fxcrt/cfx_binarybuf.cpp
@@ -20,10 +20,9 @@ CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size)
CFX_BinaryBuf::~CFX_BinaryBuf() {}
void CFX_BinaryBuf::Delete(FX_STRSIZE start_index, FX_STRSIZE count) {
- if (!m_pBuffer || start_index < 0 || count < 0 || count > m_DataSize ||
- start_index > m_DataSize - count) {
+ if (!m_pBuffer || count > m_DataSize || start_index > m_DataSize - count)
return;
- }
+
memmove(m_pBuffer.get() + start_index, m_pBuffer.get() + start_index + count,
m_DataSize - start_index - count);
m_DataSize -= count;
diff --git a/core/fxcrt/cfx_bytestring.cpp b/core/fxcrt/cfx_bytestring.cpp
index ab7c9aee99..20497ecc32 100644
--- a/core/fxcrt/cfx_bytestring.cpp
+++ b/core/fxcrt/cfx_bytestring.cpp
@@ -90,20 +90,14 @@ static_assert(sizeof(CFX_ByteString) <= sizeof(char*),
"Strings must not require more space than pointers");
CFX_ByteString::CFX_ByteString(const char* pStr, FX_STRSIZE nLen) {
- ASSERT(nLen >= 0);
- if (nLen < 0)
- nLen = pStr ? FXSYS_strlen(pStr) : 0;
-
if (nLen)
m_pData.Reset(StringData::Create(pStr, nLen));
}
CFX_ByteString::CFX_ByteString(const uint8_t* pStr, FX_STRSIZE nLen) {
- ASSERT(nLen >= 0);
- if (nLen > 0) {
+ if (nLen)
m_pData.Reset(
StringData::Create(reinterpret_cast<const char*>(pStr), nLen));
- }
}
CFX_ByteString::CFX_ByteString() {}
@@ -302,7 +296,7 @@ void CFX_ByteString::ReallocBeforeWrite(FX_STRSIZE nNewLength) {
if (m_pData && m_pData->CanOperateInPlace(nNewLength))
return;
- if (nNewLength <= 0) {
+ if (nNewLength == 0) {
clear();
return;
}
@@ -323,7 +317,7 @@ void CFX_ByteString::AllocBeforeWrite(FX_STRSIZE nNewLength) {
if (m_pData && m_pData->CanOperateInPlace(nNewLength))
return;
- if (nNewLength <= 0) {
+ if (nNewLength == 0) {
clear();
return;
}
@@ -332,7 +326,6 @@ void CFX_ByteString::AllocBeforeWrite(FX_STRSIZE nNewLength) {
}
void CFX_ByteString::ReleaseBuffer(FX_STRSIZE nNewLength) {
- ASSERT(nNewLength >= 0);
if (!m_pData)
return;
@@ -387,7 +380,8 @@ FX_STRSIZE CFX_ByteString::Delete(FX_STRSIZE index, FX_STRSIZE count) {
return 0;
FX_STRSIZE old_length = m_pData->m_nDataLength;
- if (count <= 0 || index != pdfium::clamp(index, 0, old_length))
+ if (count == 0 ||
+ index != pdfium::clamp(index, static_cast<FX_STRSIZE>(0), old_length))
return old_length;
FX_STRSIZE removal_length = index + count;
@@ -403,7 +397,7 @@ FX_STRSIZE CFX_ByteString::Delete(FX_STRSIZE index, FX_STRSIZE count) {
}
void CFX_ByteString::Concat(const char* pSrcData, FX_STRSIZE nSrcLen) {
- if (!pSrcData || nSrcLen <= 0)
+ if (!pSrcData || nSrcLen == 0)
return;
if (!m_pData) {
@@ -460,7 +454,7 @@ CFX_ByteString CFX_ByteString::Right(FX_STRSIZE count) const {
void CFX_ByteString::AllocCopy(CFX_ByteString& dest,
FX_STRSIZE nCopyLen,
FX_STRSIZE nCopyIndex) const {
- if (nCopyLen <= 0)
+ if (nCopyLen == 0)
return;
CFX_RetainPtr<StringData> pNewData(
@@ -700,13 +694,13 @@ int CFX_ByteString::Compare(const CFX_ByteStringC& str) const {
}
void CFX_ByteString::TrimRight(const CFX_ByteStringC& pTargets) {
- if (!m_pData || pTargets.IsEmpty()) {
+ if (!m_pData || pTargets.IsEmpty())
return;
- }
+
FX_STRSIZE pos = GetLength();
- if (pos < 1) {
+ if (pos == 0)
return;
- }
+
while (pos) {
FX_STRSIZE i = 0;
while (i < pTargets.GetLength() &&
@@ -738,7 +732,7 @@ void CFX_ByteString::TrimLeft(const CFX_ByteStringC& pTargets) {
return;
FX_STRSIZE len = GetLength();
- if (len < 1)
+ if (len == 0)
return;
FX_STRSIZE pos = 0;
diff --git a/core/fxcrt/cfx_bytestring.h b/core/fxcrt/cfx_bytestring.h
index 261060bda0..432f28a06d 100644
--- a/core/fxcrt/cfx_bytestring.h
+++ b/core/fxcrt/cfx_bytestring.h
@@ -82,14 +82,8 @@ class CFX_ByteString {
return m_pData ? FXSYS_strlen(m_pData->m_String) : 0;
}
bool IsEmpty() const { return !GetLength(); }
-
- bool IsValidIndex(FX_STRSIZE index) const {
- return 0 <= index && index < GetLength();
- }
-
- bool IsValidLength(FX_STRSIZE length) const {
- return 0 <= length && length <= GetLength();
- }
+ bool IsValidIndex(FX_STRSIZE index) const { return index < GetLength(); }
+ bool IsValidLength(FX_STRSIZE length) const { return length <= GetLength(); }
int Compare(const CFX_ByteStringC& str) const;
bool EqualNoCase(const CFX_ByteStringC& str) const;
diff --git a/core/fxcrt/cfx_bytestring_unittest.cpp b/core/fxcrt/cfx_bytestring_unittest.cpp
index a590af3b14..415b4621a1 100644
--- a/core/fxcrt/cfx_bytestring_unittest.cpp
+++ b/core/fxcrt/cfx_bytestring_unittest.cpp
@@ -291,7 +291,7 @@ TEST(fxcrt, ByteStringOperatorNE) {
TEST(fxcrt, ByteStringCNull) {
CFX_ByteStringC null_string;
EXPECT_FALSE(null_string.raw_str());
- EXPECT_EQ(0, null_string.GetLength());
+ EXPECT_EQ(0u, null_string.GetLength());
EXPECT_TRUE(null_string.IsEmpty());
CFX_ByteStringC another_null_string;
@@ -299,27 +299,27 @@ TEST(fxcrt, ByteStringCNull) {
CFX_ByteStringC copied_null_string(null_string);
EXPECT_FALSE(copied_null_string.raw_str());
- EXPECT_EQ(0, copied_null_string.GetLength());
+ EXPECT_EQ(0u, copied_null_string.GetLength());
EXPECT_TRUE(copied_null_string.IsEmpty());
EXPECT_EQ(null_string, copied_null_string);
CFX_ByteStringC empty_string(""); // Pointer to NUL, not NULL pointer.
EXPECT_TRUE(empty_string.raw_str());
- EXPECT_EQ(0, empty_string.GetLength());
+ EXPECT_EQ(0u, empty_string.GetLength());
EXPECT_TRUE(empty_string.IsEmpty());
EXPECT_EQ(null_string, empty_string);
CFX_ByteStringC assigned_null_string("initially not nullptr");
assigned_null_string = null_string;
EXPECT_FALSE(assigned_null_string.raw_str());
- EXPECT_EQ(0, assigned_null_string.GetLength());
+ EXPECT_EQ(0u, assigned_null_string.GetLength());
EXPECT_TRUE(assigned_null_string.IsEmpty());
EXPECT_EQ(null_string, assigned_null_string);
CFX_ByteStringC assigned_nullptr_string("initially not nullptr");
assigned_nullptr_string = nullptr;
EXPECT_FALSE(assigned_nullptr_string.raw_str());
- EXPECT_EQ(0, assigned_nullptr_string.GetLength());
+ EXPECT_EQ(0u, assigned_nullptr_string.GetLength());
EXPECT_TRUE(assigned_nullptr_string.IsEmpty());
EXPECT_EQ(null_string, assigned_nullptr_string);
@@ -414,31 +414,31 @@ TEST(fxcrt, ByteStringReplace) {
TEST(fxcrt, ByteStringInsert) {
CFX_ByteString fred("FRED");
- EXPECT_EQ(4, fred.Insert(-1, 'X'));
+ EXPECT_EQ(4u, fred.Insert(-1, 'X'));
EXPECT_EQ("FRED", fred);
- EXPECT_EQ(5, fred.Insert(0, 'S'));
+ EXPECT_EQ(5u, fred.Insert(0, 'S'));
EXPECT_EQ("SFRED", fred);
- EXPECT_EQ(6, fred.Insert(1, 'T'));
+ EXPECT_EQ(6u, fred.Insert(1, 'T'));
EXPECT_EQ("STFRED", fred);
- EXPECT_EQ(7, fred.Insert(4, 'U'));
+ EXPECT_EQ(7u, fred.Insert(4, 'U'));
EXPECT_EQ("STFRUED", fred);
- EXPECT_EQ(8, fred.Insert(7, 'V'));
+ EXPECT_EQ(8u, fred.Insert(7, 'V'));
EXPECT_EQ("STFRUEDV", fred);
- EXPECT_EQ(8, fred.Insert(12, 'P'));
+ EXPECT_EQ(8u, fred.Insert(12, 'P'));
EXPECT_EQ("STFRUEDV", fred);
{
CFX_ByteString empty;
- EXPECT_EQ(0, empty.Insert(-1, 'X'));
+ EXPECT_EQ(0u, empty.Insert(-1, 'X'));
EXPECT_NE("X", empty);
}
{
CFX_ByteString empty;
- EXPECT_EQ(1, empty.Insert(0, 'X'));
+ EXPECT_EQ(1u, empty.Insert(0, 'X'));
EXPECT_EQ("X", empty);
}
{
CFX_ByteString empty;
- EXPECT_EQ(0, empty.Insert(5, 'X'));
+ EXPECT_EQ(0u, empty.Insert(5, 'X'));
EXPECT_NE("X", empty);
}
}
@@ -446,60 +446,60 @@ TEST(fxcrt, ByteStringInsert) {
TEST(fxcrt, ByteStringInsertAtFrontAndInsertAtBack) {
{
CFX_ByteString empty;
- EXPECT_EQ(1, empty.InsertAtFront('D'));
+ EXPECT_EQ(1u, empty.InsertAtFront('D'));
EXPECT_EQ("D", empty);
- EXPECT_EQ(2, empty.InsertAtFront('E'));
+ EXPECT_EQ(2u, empty.InsertAtFront('E'));
EXPECT_EQ("ED", empty);
- EXPECT_EQ(3, empty.InsertAtFront('R'));
+ EXPECT_EQ(3u, empty.InsertAtFront('R'));
EXPECT_EQ("RED", empty);
- EXPECT_EQ(4, empty.InsertAtFront('F'));
+ EXPECT_EQ(4u, empty.InsertAtFront('F'));
EXPECT_EQ("FRED", empty);
}
{
CFX_ByteString empty;
- EXPECT_EQ(1, empty.InsertAtBack('F'));
+ EXPECT_EQ(1u, empty.InsertAtBack('F'));
EXPECT_EQ("F", empty);
- EXPECT_EQ(2, empty.InsertAtBack('R'));
+ EXPECT_EQ(2u, empty.InsertAtBack('R'));
EXPECT_EQ("FR", empty);
- EXPECT_EQ(3, empty.InsertAtBack('E'));
+ EXPECT_EQ(3u, empty.InsertAtBack('E'));
EXPECT_EQ("FRE", empty);
- EXPECT_EQ(4, empty.InsertAtBack('D'));
+ EXPECT_EQ(4u, empty.InsertAtBack('D'));
EXPECT_EQ("FRED", empty);
}
{
CFX_ByteString empty;
- EXPECT_EQ(1, empty.InsertAtBack('E'));
+ EXPECT_EQ(1u, empty.InsertAtBack('E'));
EXPECT_EQ("E", empty);
- EXPECT_EQ(2, empty.InsertAtFront('R'));
+ EXPECT_EQ(2u, empty.InsertAtFront('R'));
EXPECT_EQ("RE", empty);
- EXPECT_EQ(3, empty.InsertAtBack('D'));
+ EXPECT_EQ(3u, empty.InsertAtBack('D'));
EXPECT_EQ("RED", empty);
- EXPECT_EQ(4, empty.InsertAtFront('F'));
+ EXPECT_EQ(4u, empty.InsertAtFront('F'));
EXPECT_EQ("FRED", empty);
}
}
TEST(fxcrt, ByteStringDelete) {
CFX_ByteString fred("FRED");
- EXPECT_EQ(4, fred.Delete(0, 0));
+ EXPECT_EQ(4u, fred.Delete(0, 0));
EXPECT_EQ("FRED", fred);
- EXPECT_EQ(2, fred.Delete(0, 2));
+ EXPECT_EQ(2u, fred.Delete(0, 2));
EXPECT_EQ("ED", fred);
- EXPECT_EQ(1, fred.Delete(1));
+ EXPECT_EQ(1u, fred.Delete(1));
EXPECT_EQ("E", fred);
- EXPECT_EQ(1, fred.Delete(-1));
+ EXPECT_EQ(1u, fred.Delete(-1));
EXPECT_EQ("E", fred);
- EXPECT_EQ(0, fred.Delete(0));
+ EXPECT_EQ(0u, fred.Delete(0));
EXPECT_EQ("", fred);
- EXPECT_EQ(0, fred.Delete(0));
+ EXPECT_EQ(0u, fred.Delete(0));
EXPECT_EQ("", fred);
CFX_ByteString empty;
- EXPECT_EQ(0, empty.Delete(0));
+ EXPECT_EQ(0u, empty.Delete(0));
EXPECT_EQ("", empty);
- EXPECT_EQ(0, empty.Delete(-1));
+ EXPECT_EQ(0u, empty.Delete(-1));
EXPECT_EQ("", empty);
- EXPECT_EQ(0, empty.Delete(1));
+ EXPECT_EQ(0u, empty.Delete(1));
EXPECT_EQ("", empty);
}
@@ -574,32 +574,32 @@ TEST(fxcrt, ByteStringFind) {
CFX_ByteString single_string("a");
result = single_string.Find('a');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(0, result.value());
+ EXPECT_EQ(0u, result.value());
EXPECT_FALSE(single_string.Find('b').has_value());
EXPECT_FALSE(single_string.Find('\0').has_value());
CFX_ByteString longer_string("abccc");
result = longer_string.Find('a');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(0, result.value());
+ EXPECT_EQ(0u, result.value());
result = longer_string.Find('c');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(2, result.value());
+ EXPECT_EQ(2u, result.value());
result = longer_string.Find('c', 3);
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(3, result.value());
+ EXPECT_EQ(3u, result.value());
EXPECT_FALSE(longer_string.Find('d').has_value());
EXPECT_FALSE(longer_string.Find('\0').has_value());
result = longer_string.Find("ab");
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(0, result.value());
+ EXPECT_EQ(0u, result.value());
result = longer_string.Find("ccc");
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(2, result.value());
+ EXPECT_EQ(2u, result.value());
result = longer_string.Find("cc", 3);
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(3, result.value());
+ EXPECT_EQ(3u, result.value());
EXPECT_FALSE(longer_string.Find("d").has_value());
CFX_ByteString hibyte_string(
@@ -607,7 +607,7 @@ TEST(fxcrt, ByteStringFind) {
"def");
result = hibyte_string.Find('\x8c');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(2, result.value());
+ EXPECT_EQ(2u, result.value());
}
TEST(fxcrt, ByteStringReverseFind) {
@@ -623,17 +623,17 @@ TEST(fxcrt, ByteStringReverseFind) {
CFX_ByteString single_string("a");
result = single_string.ReverseFind('a');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(0, result.value());
+ EXPECT_EQ(0u, result.value());
EXPECT_FALSE(single_string.ReverseFind('b').has_value());
EXPECT_FALSE(single_string.ReverseFind('\0').has_value());
CFX_ByteString longer_string("abccc");
result = longer_string.ReverseFind('a');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(0, result.value());
+ EXPECT_EQ(0u, result.value());
result = longer_string.ReverseFind('c');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(4, result.value());
+ EXPECT_EQ(4u, result.value());
EXPECT_FALSE(longer_string.ReverseFind('\0').has_value());
CFX_ByteString hibyte_string(
@@ -641,7 +641,7 @@ TEST(fxcrt, ByteStringReverseFind) {
"def");
result = hibyte_string.ReverseFind('\x8c');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(2, result.value());
+ EXPECT_EQ(2u, result.value());
}
TEST(fxcrt, ByteStringUpperLower) {
@@ -862,11 +862,11 @@ TEST(fxcrt, ByteStringCNotNull) {
CFX_ByteStringC embedded_nul_string7("abc\0def", 7);
CFX_ByteStringC illegal_string7("abcdef", 7);
- EXPECT_EQ(3, string3.GetLength());
- EXPECT_EQ(6, string6.GetLength());
- EXPECT_EQ(3, alternate_string3.GetLength());
- EXPECT_EQ(7, embedded_nul_string7.GetLength());
- EXPECT_EQ(7, illegal_string7.GetLength());
+ EXPECT_EQ(3u, string3.GetLength());
+ EXPECT_EQ(6u, string6.GetLength());
+ EXPECT_EQ(3u, alternate_string3.GetLength());
+ EXPECT_EQ(7u, embedded_nul_string7.GetLength());
+ EXPECT_EQ(7u, illegal_string7.GetLength());
EXPECT_NE(string3, string6);
EXPECT_EQ(string3, alternate_string3);
@@ -913,10 +913,10 @@ TEST(fxcrt, ByteStringCFromChar) {
CFX_ByteStringC lower_a_string_from_char(lower_a);
// Pointer to nul, not nullptr ptr, hence length 1 ...
- EXPECT_EQ(1, nul_string_from_char.GetLength());
+ EXPECT_EQ(1u, nul_string_from_char.GetLength());
EXPECT_NE(null_string, nul_string_from_char);
- EXPECT_EQ(1, lower_a_string_from_char.GetLength());
+ EXPECT_EQ(1u, lower_a_string_from_char.GetLength());
EXPECT_EQ(lower_a_string, lower_a_string_from_char);
EXPECT_NE(nul_string_from_char, lower_a_string_from_char);
@@ -927,18 +927,18 @@ TEST(fxcrt, ByteStringCFromChar) {
TEST(fxcrt, ByteStringCFromVector) {
std::vector<uint8_t> null_vec;
CFX_ByteStringC null_string(null_vec);
- EXPECT_EQ(0, null_string.GetLength());
+ EXPECT_EQ(0u, null_string.GetLength());
std::vector<uint8_t> lower_a_vec(10, static_cast<uint8_t>('a'));
CFX_ByteStringC lower_a_string(lower_a_vec);
- EXPECT_EQ(10, lower_a_string.GetLength());
+ EXPECT_EQ(static_cast<FX_STRSIZE>(10), lower_a_string.GetLength());
EXPECT_EQ("aaaaaaaaaa", lower_a_string);
std::vector<uint8_t> cleared_vec;
cleared_vec.push_back(42);
cleared_vec.pop_back();
CFX_ByteStringC cleared_string(cleared_vec);
- EXPECT_EQ(0, cleared_string.GetLength());
+ EXPECT_EQ(0u, cleared_string.GetLength());
EXPECT_EQ(nullptr, cleared_string.raw_str());
}
@@ -969,17 +969,17 @@ TEST(fxcrt, ByteStringCFind) {
CFX_ByteStringC single_string("a");
result = single_string.Find('a');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(0, result.value());
+ EXPECT_EQ(0u, result.value());
EXPECT_FALSE(single_string.Find('b').has_value());
EXPECT_FALSE(single_string.Find('\0').has_value());
CFX_ByteStringC longer_string("abccc");
result = longer_string.Find('a');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(0, result.value());
+ EXPECT_EQ(0u, result.value());
result = longer_string.Find('c');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(2, result.value());
+ EXPECT_EQ(2u, result.value());
EXPECT_FALSE(longer_string.Find('d').has_value());
EXPECT_FALSE(longer_string.Find('\0').has_value());
@@ -988,7 +988,7 @@ TEST(fxcrt, ByteStringCFind) {
"def");
result = hibyte_string.Find('\x8c');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(2, result.value());
+ EXPECT_EQ(2u, result.value());
}
TEST(fxcrt, ByteStringCMid) {
@@ -1303,9 +1303,9 @@ TEST(fxcrt, ByteStringFormatPrecision) {
TEST(fxcrt, EmptyByteString) {
CFX_ByteString empty_str;
EXPECT_TRUE(empty_str.IsEmpty());
- EXPECT_EQ(0, empty_str.GetLength());
+ EXPECT_EQ(0u, empty_str.GetLength());
const char* cstr = empty_str.c_str();
- EXPECT_EQ(0, FXSYS_strlen(cstr));
+ EXPECT_EQ(0u, FXSYS_strlen(cstr));
}
TEST(fxcrt, ByteStringInitializerList) {
@@ -1420,7 +1420,7 @@ TEST(fxcrt, OStreamByteStringOverload) {
// Writing a CFX_ByteString with nulls and no specified length treats it as
// a C-style null-terminated string.
str = CFX_ByteString(stringWithNulls);
- EXPECT_EQ(2, str.GetLength());
+ EXPECT_EQ(2u, str.GetLength());
stream.str("");
stream << str;
EXPECT_EQ(2u, stream.tellp());
@@ -1428,7 +1428,7 @@ TEST(fxcrt, OStreamByteStringOverload) {
// Writing a CFX_ByteString with nulls but specifying its length treats it as
// a C++-style string.
str = CFX_ByteString(stringWithNulls, 4);
- EXPECT_EQ(4, str.GetLength());
+ EXPECT_EQ(4u, str.GetLength());
stream.str("");
stream << str;
EXPECT_EQ(4u, stream.tellp());
@@ -1484,7 +1484,7 @@ TEST(fxcrt, OStreamByteStringCOverload) {
std::ostringstream stream;
char stringWithNulls[]{'x', 'y', '\0', 'z'};
CFX_ByteStringC str(stringWithNulls);
- EXPECT_EQ(2, str.GetLength());
+ EXPECT_EQ(2u, str.GetLength());
stream << str;
EXPECT_EQ(2u, stream.tellp());
str = "";
@@ -1496,7 +1496,7 @@ TEST(fxcrt, OStreamByteStringCOverload) {
std::ostringstream stream;
char stringWithNulls[]{'x', 'y', '\0', 'z'};
CFX_ByteStringC str(stringWithNulls, 4);
- EXPECT_EQ(4, str.GetLength());
+ EXPECT_EQ(4u, str.GetLength());
stream << str;
EXPECT_EQ(4u, stream.tellp());
str = "";
diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp
index a67ec52c85..d3516e1794 100644
--- a/core/fxcrt/cfx_seekablestreamproxy.cpp
+++ b/core/fxcrt/cfx_seekablestreamproxy.cpp
@@ -105,9 +105,6 @@ void UTF16ToWChar(void* pBuffer, FX_STRSIZE iLength) {
void SwapByteOrder(wchar_t* pStr, FX_STRSIZE iLength) {
ASSERT(pStr);
- if (iLength < 0)
- iLength = FXSYS_wcslen(pStr);
-
uint16_t wch;
if (sizeof(wchar_t) > 2) {
while (iLength-- > 0) {
@@ -230,7 +227,7 @@ FX_STRSIZE CFX_SeekableStreamProxy::ReadData(uint8_t* pBuffer,
FX_STRSIZE CFX_SeekableStreamProxy::ReadString(wchar_t* pStr,
FX_STRSIZE iMaxLength,
bool* bEOS) {
- if (!pStr || iMaxLength <= 0)
+ if (!pStr || iMaxLength == 0)
return 0;
if (m_IsWriteStream)
diff --git a/core/fxcrt/cfx_string_c_template.h b/core/fxcrt/cfx_string_c_template.h
index 6bc71d853d..8585d73ae6 100644
--- a/core/fxcrt/cfx_string_c_template.h
+++ b/core/fxcrt/cfx_string_c_template.h
@@ -36,8 +36,7 @@ class CFX_StringCTemplate {
m_Length(ptr ? FXSYS_len(ptr) : 0) {}
CFX_StringCTemplate(const CharType* ptr, FX_STRSIZE len)
- : m_Ptr(reinterpret_cast<const UnsignedType*>(ptr)),
- m_Length(len < 0 ? FXSYS_len(ptr) : len) {}
+ : m_Ptr(reinterpret_cast<const UnsignedType*>(ptr)), m_Length(len) {}
template <typename U = UnsignedType>
CFX_StringCTemplate(
@@ -106,7 +105,7 @@ class CFX_StringCTemplate {
return 0;
uint32_t strid = 0;
- FX_STRSIZE size = std::min(4, m_Length);
+ FX_STRSIZE size = std::min(static_cast<FX_STRSIZE>(4), m_Length);
for (FX_STRSIZE i = 0; i < size; i++)
strid = strid * 256 + m_Ptr.Get()[i];
@@ -119,16 +118,9 @@ class CFX_StringCTemplate {
}
FX_STRSIZE GetLength() const { return m_Length; }
-
bool IsEmpty() const { return m_Length == 0; }
-
- bool IsValidIndex(FX_STRSIZE index) const {
- return 0 <= index && index < GetLength();
- }
-
- bool IsValidLength(FX_STRSIZE length) const {
- return 0 <= length && length <= GetLength();
- }
+ bool IsValidIndex(FX_STRSIZE index) const { return index < GetLength(); }
+ bool IsValidLength(FX_STRSIZE length) const { return length <= GetLength(); }
const UnsignedType& operator[](const FX_STRSIZE index) const {
ASSERT(IsValidIndex(index));
diff --git a/core/fxcrt/cfx_widestring.cpp b/core/fxcrt/cfx_widestring.cpp
index 05a4fc3b5e..24b7fb59d3 100644
--- a/core/fxcrt/cfx_widestring.cpp
+++ b/core/fxcrt/cfx_widestring.cpp
@@ -293,10 +293,6 @@ CFX_WideString::CFX_WideString(CFX_WideString&& other) noexcept {
}
CFX_WideString::CFX_WideString(const wchar_t* pStr, FX_STRSIZE nLen) {
- ASSERT(nLen >= 0);
- if (nLen < 0)
- nLen = pStr ? FXSYS_wcslen(pStr) : 0;
-
if (nLen)
m_pData.Reset(StringData::Create(pStr, nLen));
}
@@ -413,7 +409,7 @@ bool CFX_WideString::operator==(const wchar_t* ptr) const {
if (!ptr)
return m_pData->m_nDataLength == 0;
- return wcslen(ptr) == static_cast<size_t>(m_pData->m_nDataLength) &&
+ return wcslen(ptr) == m_pData->m_nDataLength &&
wmemcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0;
}
@@ -481,7 +477,7 @@ void CFX_WideString::AllocBeforeWrite(FX_STRSIZE nNewLength) {
if (m_pData && m_pData->CanOperateInPlace(nNewLength))
return;
- if (nNewLength <= 0) {
+ if (nNewLength == 0) {
clear();
return;
}
@@ -490,7 +486,6 @@ void CFX_WideString::AllocBeforeWrite(FX_STRSIZE nNewLength) {
}
void CFX_WideString::ReleaseBuffer(FX_STRSIZE nNewLength) {
- ASSERT(nNewLength >= 0);
if (!m_pData)
return;
@@ -545,7 +540,8 @@ FX_STRSIZE CFX_WideString::Delete(FX_STRSIZE index, FX_STRSIZE count) {
return 0;
FX_STRSIZE old_length = m_pData->m_nDataLength;
- if (count <= 0 || index != pdfium::clamp(index, 0, old_length))
+ if (count == 0 ||
+ index != pdfium::clamp(index, static_cast<FX_STRSIZE>(0), old_length))
return old_length;
FX_STRSIZE removal_length = index + count;
@@ -561,7 +557,7 @@ FX_STRSIZE CFX_WideString::Delete(FX_STRSIZE index, FX_STRSIZE count) {
}
void CFX_WideString::Concat(const wchar_t* pSrcData, FX_STRSIZE nSrcLen) {
- if (!pSrcData || nSrcLen <= 0)
+ if (!pSrcData || nSrcLen == 0)
return;
if (!m_pData) {
@@ -639,7 +635,7 @@ CFX_WideString CFX_WideString::Right(FX_STRSIZE count) const {
void CFX_WideString::AllocCopy(CFX_WideString& dest,
FX_STRSIZE nCopyLen,
FX_STRSIZE nCopyIndex) const {
- if (nCopyLen <= 0)
+ if (nCopyLen == 0)
return;
CFX_RetainPtr<StringData> pNewData(
@@ -676,7 +672,7 @@ void CFX_WideString::FormatV(const wchar_t* format, va_list argList) {
auto guess = GuessSizeForVSWPrintf(format, argListCopy);
if (!guess.has_value())
return;
- maxLen = guess.value();
+ maxLen = pdfium::base::checked_cast<int>(guess.value());
}
while (maxLen < 32 * 1024) {
FX_VA_COPY(argListCopy, argList);
@@ -864,7 +860,7 @@ CFX_WideString CFX_WideString::FromUTF8(const CFX_ByteStringC& str) {
// static
CFX_WideString CFX_WideString::FromUTF16LE(const unsigned short* wstr,
FX_STRSIZE wlen) {
- if (!wstr || wlen <= 0) {
+ if (!wstr || wlen == 0) {
return CFX_WideString();
}
@@ -963,7 +959,7 @@ void CFX_WideString::TrimLeft(const CFX_WideStringC& pTargets) {
return;
FX_STRSIZE len = GetLength();
- if (len < 1)
+ if (len == 0)
return;
FX_STRSIZE pos = 0;
@@ -978,13 +974,14 @@ void CFX_WideString::TrimLeft(const CFX_WideStringC& pTargets) {
}
pos++;
}
- if (pos) {
- ReallocBeforeWrite(len);
- FX_STRSIZE nDataLength = len - pos;
- memmove(m_pData->m_String, m_pData->m_String + pos,
- (nDataLength + 1) * sizeof(wchar_t));
- m_pData->m_nDataLength = nDataLength;
- }
+ if (!pos)
+ return;
+
+ ReallocBeforeWrite(len);
+ FX_STRSIZE nDataLength = len - pos;
+ memmove(m_pData->m_String, m_pData->m_String + pos,
+ (nDataLength + 1) * sizeof(wchar_t));
+ m_pData->m_nDataLength = nDataLength;
}
void CFX_WideString::TrimLeft(wchar_t chTarget) {
diff --git a/core/fxcrt/cfx_widestring.h b/core/fxcrt/cfx_widestring.h
index 100fec6706..9922e4277a 100644
--- a/core/fxcrt/cfx_widestring.h
+++ b/core/fxcrt/cfx_widestring.h
@@ -80,14 +80,8 @@ class CFX_WideString {
return m_pData ? FXSYS_wcslen(m_pData->m_String) : 0;
}
bool IsEmpty() const { return !GetLength(); }
-
- bool IsValidIndex(FX_STRSIZE index) const {
- return 0 <= index && index < GetLength();
- }
-
- bool IsValidLength(FX_STRSIZE length) const {
- return 0 <= length && length <= GetLength();
- }
+ bool IsValidIndex(FX_STRSIZE index) const { return index < GetLength(); }
+ bool IsValidLength(FX_STRSIZE length) const { return length <= GetLength(); }
const CFX_WideString& operator=(const wchar_t* str);
const CFX_WideString& operator=(const CFX_WideString& stringSrc);
diff --git a/core/fxcrt/cfx_widestring_unittest.cpp b/core/fxcrt/cfx_widestring_unittest.cpp
index 0005cb3754..1408d10f15 100644
--- a/core/fxcrt/cfx_widestring_unittest.cpp
+++ b/core/fxcrt/cfx_widestring_unittest.cpp
@@ -373,31 +373,31 @@ TEST(fxcrt, WideStringReplace) {
TEST(fxcrt, WideStringInsert) {
CFX_WideString fred(L"FRED");
- EXPECT_EQ(4, fred.Insert(-1, 'X'));
+ EXPECT_EQ(4u, fred.Insert(-1, 'X'));
EXPECT_EQ(L"FRED", fred);
- EXPECT_EQ(5, fred.Insert(0, 'S'));
+ EXPECT_EQ(5u, fred.Insert(0, 'S'));
EXPECT_EQ(L"SFRED", fred);
- EXPECT_EQ(6, fred.Insert(1, 'T'));
+ EXPECT_EQ(6u, fred.Insert(1, 'T'));
EXPECT_EQ(L"STFRED", fred);
- EXPECT_EQ(7, fred.Insert(4, 'U'));
+ EXPECT_EQ(7u, fred.Insert(4, 'U'));
EXPECT_EQ(L"STFRUED", fred);
- EXPECT_EQ(8, fred.Insert(7, 'V'));
+ EXPECT_EQ(8u, fred.Insert(7, 'V'));
EXPECT_EQ(L"STFRUEDV", fred);
- EXPECT_EQ(8, fred.Insert(12, 'P'));
+ EXPECT_EQ(8u, fred.Insert(12, 'P'));
EXPECT_EQ(L"STFRUEDV", fred);
{
CFX_WideString empty;
- EXPECT_EQ(0, empty.Insert(-1, 'X'));
+ EXPECT_EQ(0u, empty.Insert(-1, 'X'));
EXPECT_NE(L"X", empty);
}
{
CFX_WideString empty;
- EXPECT_EQ(1, empty.Insert(0, 'X'));
+ EXPECT_EQ(1u, empty.Insert(0, 'X'));
EXPECT_EQ(L"X", empty);
}
{
CFX_WideString empty;
- EXPECT_EQ(0, empty.Insert(5, 'X'));
+ EXPECT_EQ(0u, empty.Insert(5, 'X'));
EXPECT_NE(L"X", empty);
}
}
@@ -405,60 +405,60 @@ TEST(fxcrt, WideStringInsert) {
TEST(fxcrt, WideStringInsertAtFrontAndInsertAtBack) {
{
CFX_WideString empty;
- EXPECT_EQ(1, empty.InsertAtFront('D'));
+ EXPECT_EQ(1u, empty.InsertAtFront('D'));
EXPECT_EQ(L"D", empty);
- EXPECT_EQ(2, empty.InsertAtFront('E'));
+ EXPECT_EQ(2u, empty.InsertAtFront('E'));
EXPECT_EQ(L"ED", empty);
- EXPECT_EQ(3, empty.InsertAtFront('R'));
+ EXPECT_EQ(3u, empty.InsertAtFront('R'));
EXPECT_EQ(L"RED", empty);
- EXPECT_EQ(4, empty.InsertAtFront('F'));
+ EXPECT_EQ(4u, empty.InsertAtFront('F'));
EXPECT_EQ(L"FRED", empty);
}
{
CFX_WideString empty;
- EXPECT_EQ(1, empty.InsertAtBack('F'));
+ EXPECT_EQ(1u, empty.InsertAtBack('F'));
EXPECT_EQ(L"F", empty);
- EXPECT_EQ(2, empty.InsertAtBack('R'));
+ EXPECT_EQ(2u, empty.InsertAtBack('R'));
EXPECT_EQ(L"FR", empty);
- EXPECT_EQ(3, empty.InsertAtBack('E'));
+ EXPECT_EQ(3u, empty.InsertAtBack('E'));
EXPECT_EQ(L"FRE", empty);
- EXPECT_EQ(4, empty.InsertAtBack('D'));
+ EXPECT_EQ(4u, empty.InsertAtBack('D'));
EXPECT_EQ(L"FRED", empty);
}
{
CFX_WideString empty;
- EXPECT_EQ(1, empty.InsertAtBack('E'));
+ EXPECT_EQ(1u, empty.InsertAtBack('E'));
EXPECT_EQ(L"E", empty);
- EXPECT_EQ(2, empty.InsertAtFront('R'));
+ EXPECT_EQ(2u, empty.InsertAtFront('R'));
EXPECT_EQ(L"RE", empty);
- EXPECT_EQ(3, empty.InsertAtBack('D'));
+ EXPECT_EQ(3u, empty.InsertAtBack('D'));
EXPECT_EQ(L"RED", empty);
- EXPECT_EQ(4, empty.InsertAtFront('F'));
+ EXPECT_EQ(4u, empty.InsertAtFront('F'));
EXPECT_EQ(L"FRED", empty);
}
}
TEST(fxcrt, WideStringDelete) {
CFX_WideString fred(L"FRED");
- EXPECT_EQ(4, fred.Delete(0, 0));
+ EXPECT_EQ(4u, fred.Delete(0, 0));
EXPECT_EQ(L"FRED", fred);
- EXPECT_EQ(2, fred.Delete(0, 2));
+ EXPECT_EQ(2u, fred.Delete(0, 2));
EXPECT_EQ(L"ED", fred);
- EXPECT_EQ(1, fred.Delete(1));
+ EXPECT_EQ(1u, fred.Delete(1));
EXPECT_EQ(L"E", fred);
- EXPECT_EQ(1, fred.Delete(-1));
+ EXPECT_EQ(1u, fred.Delete(-1));
EXPECT_EQ(L"E", fred);
- EXPECT_EQ(0, fred.Delete(0));
+ EXPECT_EQ(0u, fred.Delete(0));
EXPECT_EQ(L"", fred);
- EXPECT_EQ(0, fred.Delete(0));
+ EXPECT_EQ(0u, fred.Delete(0));
EXPECT_EQ(L"", fred);
CFX_WideString empty;
- EXPECT_EQ(0, empty.Delete(0));
+ EXPECT_EQ(0u, empty.Delete(0));
EXPECT_EQ(L"", empty);
- EXPECT_EQ(0, empty.Delete(-1));
+ EXPECT_EQ(0u, empty.Delete(-1));
EXPECT_EQ(L"", empty);
- EXPECT_EQ(0, empty.Delete(1));
+ EXPECT_EQ(0u, empty.Delete(1));
EXPECT_EQ(L"", empty);
}
@@ -533,31 +533,31 @@ TEST(fxcrt, WideStringFind) {
CFX_WideString single_string(L"a");
result = single_string.Find(L'a');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(0, result.value());
+ EXPECT_EQ(0u, result.value());
EXPECT_FALSE(single_string.Find(L'b').has_value());
EXPECT_FALSE(single_string.Find(L'\0').has_value());
CFX_WideString longer_string(L"abccc");
result = longer_string.Find(L'a');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(0, result.value());
+ EXPECT_EQ(0u, result.value());
result = longer_string.Find(L'c');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(2, result.value());
+ EXPECT_EQ(2u, result.value());
result = longer_string.Find(L'c', 3);
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(3, result.value());
+ EXPECT_EQ(3u, result.value());
EXPECT_FALSE(longer_string.Find(L'\0').has_value());
result = longer_string.Find(L"ab");
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(0, result.value());
+ EXPECT_EQ(0u, result.value());
result = longer_string.Find(L"ccc");
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(2, result.value());
+ EXPECT_EQ(2u, result.value());
result = longer_string.Find(L"cc", 3);
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(3, result.value());
+ EXPECT_EQ(3u, result.value());
EXPECT_FALSE(longer_string.Find(L"d").has_value());
CFX_WideString hibyte_string(
@@ -565,7 +565,7 @@ TEST(fxcrt, WideStringFind) {
L"def");
result = hibyte_string.Find(L'\xff8c');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(2, result.value());
+ EXPECT_EQ(2u, result.value());
}
TEST(fxcrt, WideStringUpperLower) {
@@ -800,19 +800,19 @@ TEST(fxcrt, WideStringUTF16LE_Encode) {
TEST(fxcrt, WideStringCFromVector) {
std::vector<CFX_WideStringC::UnsignedType> null_vec;
CFX_WideStringC null_string(null_vec);
- EXPECT_EQ(0, null_string.GetLength());
+ EXPECT_EQ(0u, null_string.GetLength());
std::vector<CFX_WideStringC::UnsignedType> lower_a_vec(
10, static_cast<CFX_WideStringC::UnsignedType>(L'a'));
CFX_WideStringC lower_a_string(lower_a_vec);
- EXPECT_EQ(10, lower_a_string.GetLength());
+ EXPECT_EQ(10u, lower_a_string.GetLength());
EXPECT_EQ(L"aaaaaaaaaa", lower_a_string);
std::vector<CFX_WideStringC::UnsignedType> cleared_vec;
cleared_vec.push_back(42);
cleared_vec.pop_back();
CFX_WideStringC cleared_string(cleared_vec);
- EXPECT_EQ(0, cleared_string.GetLength());
+ EXPECT_EQ(0u, cleared_string.GetLength());
EXPECT_EQ(nullptr, cleared_string.raw_str());
}
@@ -976,17 +976,17 @@ TEST(fxcrt, WideStringCFind) {
CFX_WideStringC single_string(L"a");
result = single_string.Find(L'a');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(0, result.value());
+ EXPECT_EQ(0u, result.value());
EXPECT_FALSE(single_string.Find(L'b').has_value());
EXPECT_FALSE(single_string.Find(L'\0').has_value());
CFX_WideStringC longer_string(L"abccc");
result = longer_string.Find(L'a');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(0, result.value());
+ EXPECT_EQ(0u, result.value());
result = longer_string.Find(L'c');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(2, result.value());
+ EXPECT_EQ(2u, result.value());
EXPECT_FALSE(longer_string.Find(L'd').has_value());
EXPECT_FALSE(longer_string.Find(L'\0').has_value());
@@ -995,7 +995,7 @@ TEST(fxcrt, WideStringCFind) {
L"def");
result = hibyte_string.Find(L'\xFF8c');
ASSERT_TRUE(result.has_value());
- EXPECT_EQ(2, result.value());
+ EXPECT_EQ(2u, result.value());
}
TEST(fxcrt, WideStringCNullIterator) {
@@ -1146,9 +1146,9 @@ TEST(fxcrt, WideStringFormatOutOfRangeChar) {
TEST(fxcrt, EmptyWideString) {
CFX_WideString empty_str;
EXPECT_TRUE(empty_str.IsEmpty());
- EXPECT_EQ(0, empty_str.GetLength());
+ EXPECT_EQ(0u, empty_str.GetLength());
const wchar_t* cstr = empty_str.c_str();
- EXPECT_EQ(0, FXSYS_wcslen(cstr));
+ EXPECT_EQ(0u, FXSYS_wcslen(cstr));
}
TEST(fxcrt, WidStringInitializerList) {
@@ -1255,7 +1255,7 @@ TEST(fxcrt, OStreamWideStringOverload) {
// Writing a CFX_WideString with nulls and no specified length treats it as
// a C-style null-terminated string.
str = CFX_WideString(stringWithNulls);
- EXPECT_EQ(2, str.GetLength());
+ EXPECT_EQ(2u, str.GetLength());
stream.str("");
stream << str;
EXPECT_EQ(2u, stream.tellp());
@@ -1263,7 +1263,7 @@ TEST(fxcrt, OStreamWideStringOverload) {
// Writing a CFX_WideString with nulls but specifying its length treats it as
// a C++-style string.
str = CFX_WideString(stringWithNulls, 4);
- EXPECT_EQ(4, str.GetLength());
+ EXPECT_EQ(4u, str.GetLength());
stream.str("");
stream << str;
EXPECT_EQ(4u, stream.tellp());
@@ -1309,7 +1309,7 @@ TEST(fxcrt, WideOStreamWideStringOverload) {
// Writing a CFX_WideString with nulls and no specified length treats it as
// a C-style null-terminated string.
str = CFX_WideString(stringWithNulls);
- EXPECT_EQ(2, str.GetLength());
+ EXPECT_EQ(2u, str.GetLength());
stream.str(L"");
stream << str;
EXPECT_EQ(2u, stream.tellp());
@@ -1317,7 +1317,7 @@ TEST(fxcrt, WideOStreamWideStringOverload) {
// Writing a CFX_WideString with nulls but specifying its length treats it as
// a C++-style string.
str = CFX_WideString(stringWithNulls, 4);
- EXPECT_EQ(4, str.GetLength());
+ EXPECT_EQ(4u, str.GetLength());
stream.str(L"");
stream << str;
EXPECT_EQ(4u, stream.tellp());
@@ -1381,7 +1381,7 @@ TEST(fxcrt, OStreamWideStringCOverload) {
wchar_t stringWithNulls[]{'x', 'y', '\0', 'z'};
std::ostringstream stream;
CFX_WideStringC str(stringWithNulls);
- EXPECT_EQ(2, str.GetLength());
+ EXPECT_EQ(2u, str.GetLength());
stream << str;
EXPECT_EQ(2u, stream.tellp());
str = L"";
@@ -1393,7 +1393,7 @@ TEST(fxcrt, OStreamWideStringCOverload) {
wchar_t stringWithNulls[]{'x', 'y', '\0', 'z'};
std::ostringstream stream;
CFX_WideStringC str(stringWithNulls, 4);
- EXPECT_EQ(4, str.GetLength());
+ EXPECT_EQ(4u, str.GetLength());
stream << str;
EXPECT_EQ(4u, stream.tellp());
str = L"";
@@ -1460,7 +1460,7 @@ TEST(fxcrt, WideOStreamWideStringCOverload) {
wchar_t stringWithNulls[]{'x', 'y', '\0', 'z'};
std::wostringstream stream;
CFX_WideStringC str(stringWithNulls);
- EXPECT_EQ(2, str.GetLength());
+ EXPECT_EQ(2u, str.GetLength());
stream << str;
EXPECT_EQ(2u, stream.tellp());
}
@@ -1471,7 +1471,7 @@ TEST(fxcrt, WideOStreamWideStringCOverload) {
wchar_t stringWithNulls[]{'x', 'y', '\0', 'z'};
std::wostringstream stream;
CFX_WideStringC str(stringWithNulls, 4);
- EXPECT_EQ(4, str.GetLength());
+ EXPECT_EQ(4u, str.GetLength());
stream << str;
EXPECT_EQ(4u, stream.tellp());
}
diff --git a/core/fxcrt/fx_system.h b/core/fxcrt/fx_system.h
index 1f63e6d9aa..600d71c72b 100644
--- a/core/fxcrt/fx_system.h
+++ b/core/fxcrt/fx_system.h
@@ -76,10 +76,9 @@ extern "C" {
#define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
#define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
-// PDFium string sizes are limited to 2^31-1, and the value is signed to
-// allow -1 as a placeholder for "unknown".
-// TODO(palmer): it should be a |size_t|, or at least unsigned.
-typedef int FX_STRSIZE;
+// 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
diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp
index 9228326096..92c99373cf 100644
--- a/fpdfsdk/fpdf_sysfontinfo.cpp
+++ b/fpdfsdk/fpdf_sysfontinfo.cpp
@@ -171,7 +171,7 @@ static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO* pThis,
auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
if (!pDefault->m_pFontInfo->GetFaceName(hFont, &name))
return 0;
- if (name.GetLength() >= (long)buf_size)
+ if (name.GetLength() >= static_cast<FX_STRSIZE>(buf_size))
return name.GetLength() + 1;
strncpy(buffer, name.c_str(),
diff --git a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
index 2e84df5c59..c45eadcf9a 100644
--- a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
+++ b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
@@ -122,7 +122,8 @@ CBC_ErrorCorrection::~CBC_ErrorCorrection() {}
CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords,
CBC_SymbolInfo* symbolInfo,
int32_t& e) {
- if (codewords.GetLength() != symbolInfo->dataCapacity()) {
+ if (pdfium::base::checked_cast<int32_t>(codewords.GetLength()) !=
+ symbolInfo->dataCapacity()) {
e = BCExceptionIllegalArgument;
return CFX_WideString();
}
diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
index d2f40dd060..b8c63946db 100644
--- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
@@ -118,18 +118,20 @@ CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg,
}
}
CFX_WideString codewords = context.m_codewords;
- if (codewords.GetLength() < capacity) {
+ if (pdfium::base::checked_cast<int32_t>(codewords.GetLength()) < capacity) {
codewords += PAD;
}
- while (codewords.GetLength() < capacity) {
- codewords += (randomize253State(PAD, codewords.GetLength() + 1));
+ while (pdfium::base::checked_cast<int32_t>(codewords.GetLength()) <
+ capacity) {
+ codewords += (randomize253State(
+ PAD, pdfium::base::checked_cast<int32_t>(codewords.GetLength()) + 1));
}
return codewords;
}
int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg,
int32_t startpos,
int32_t currentMode) {
- if (startpos >= msg.GetLength()) {
+ if (startpos >= pdfium::base::checked_cast<int32_t>(msg.GetLength())) {
return currentMode;
}
std::vector<float> charCounts;
@@ -151,7 +153,8 @@ int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg,
}
int32_t charsProcessed = 0;
while (true) {
- if ((startpos + charsProcessed) == msg.GetLength()) {
+ if ((startpos + charsProcessed) ==
+ pdfium::base::checked_cast<int32_t>(msg.GetLength())) {
int32_t min = std::numeric_limits<int32_t>::max();
std::vector<uint8_t> mins(6);
std::vector<int32_t> intCharCounts(6);
@@ -252,7 +255,9 @@ int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg,
}
if (intCharCounts[C40_ENCODATION] == intCharCounts[X12_ENCODATION]) {
int32_t p = startpos + charsProcessed + 1;
- while (p < msg.GetLength()) {
+ int32_t checked_length =
+ pdfium::base::checked_cast<int32_t>(msg.GetLength());
+ while (p < checked_length) {
wchar_t tc = msg[p];
if (isX12TermSep(tc)) {
return X12_ENCODATION;
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index 911730fbe5..4c488418d9 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -380,8 +380,8 @@ void MergeString(std::vector<ModeStringPair>* result,
CBC_QRCoderMode::sBYTE, versionNum, e);
if (e != BCExceptionNO)
return;
- if (element2.first == CBC_QRCoderMode::sBYTE &&
- element1.second.GetLength() < tmp) {
+ if (element2.first == CBC_QRCoderMode::sBYTE && tmp >= 0 &&
+ element1.second.GetLength() < static_cast<FX_STRSIZE>(tmp)) {
element2.second = element1.second + element2.second;
result->erase(result->begin() + i);
i--;
@@ -399,8 +399,8 @@ void MergeString(std::vector<ModeStringPair>* result,
CBC_QRCoderMode::sBYTE, versionNum, e);
if (e != BCExceptionNO)
return;
- if (element2.first == CBC_QRCoderMode::sBYTE &&
- element1.second.GetLength() < tmp) {
+ if (element2.first == CBC_QRCoderMode::sBYTE && tmp >= 0 &&
+ element1.second.GetLength() < static_cast<FX_STRSIZE>(tmp)) {
element2.second = element1.second + element2.second;
result->erase(result->begin() + i);
i--;
@@ -410,8 +410,8 @@ void MergeString(std::vector<ModeStringPair>* result,
CBC_QRCoderMode::sALPHANUMERIC, versionNum, e);
if (e != BCExceptionNO)
return;
- if (element2.first == CBC_QRCoderMode::sALPHANUMERIC &&
- element1.second.GetLength() < tmp) {
+ if (element2.first == CBC_QRCoderMode::sALPHANUMERIC && tmp >= 0 &&
+ element1.second.GetLength() < static_cast<FX_STRSIZE>(tmp)) {
element2.second = element1.second + element2.second;
result->erase(result->begin() + i);
i--;
diff --git a/testing/xfa_js_embedder_test.cpp b/testing/xfa_js_embedder_test.cpp
index d36cc815e6..a11806ffda 100644
--- a/testing/xfa_js_embedder_test.cpp
+++ b/testing/xfa_js_embedder_test.cpp
@@ -59,7 +59,8 @@ bool XFAJSEmbedderTest::Execute(const CFX_ByteStringC& input) {
CFXJSE_Value msg(GetIsolate());
value_->GetObjectPropertyByIdx(1, &msg);
- fprintf(stderr, "JS: %.*s\n", input.GetLength(), input.unterminated_c_str());
+ fprintf(stderr, "JS: %.*s\n", static_cast<int>(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/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp
index 9da8bb9583..df95a3588a 100644
--- a/xfa/fgas/crt/cfgas_formatstring.cpp
+++ b/xfa/fgas/crt/cfgas_formatstring.cpp
@@ -293,7 +293,7 @@ bool ParseLocaleDate(const CFX_WideString& wsDate,
}
}
} else if (symbol == L"YY" || symbol == L"YYYY") {
- if (*cc + symbol.GetLength() > len)
+ if (*cc + pdfium::base::checked_cast<int32_t>(symbol.GetLength()) > len)
return false;
year = 0;
@@ -417,11 +417,13 @@ bool ParseLocaleTime(const CFX_WideString& wsTime,
} else if (symbol == L"A") {
CFX_WideString wsAM = pLocale->GetMeridiemName(true);
CFX_WideString wsPM = pLocale->GetMeridiemName(false);
- if ((*cc + wsAM.GetLength() <= len) &&
+ if ((*cc + pdfium::base::checked_cast<int32_t>(wsAM.GetLength()) <=
+ len) &&
(CFX_WideStringC(str + *cc, wsAM.GetLength()) == wsAM)) {
*cc += wsAM.GetLength();
bHasA = true;
- } else if ((*cc + wsPM.GetLength() <= len) &&
+ } else if ((*cc + pdfium::base::checked_cast<int32_t>(wsPM.GetLength()) <=
+ len) &&
(CFX_WideStringC(str + *cc, wsPM.GetLength()) == wsPM)) {
*cc += wsPM.GetLength();
bHasA = true;
@@ -2087,12 +2089,13 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
if (cc >= 0) {
int nPos = dot_index.value() % 3;
wsOutput->clear();
- for (int32_t i = 0; i < dot_index; i++) {
+ for (int32_t i = 0;
+ i < pdfium::base::checked_cast<int32_t>(dot_index.value()); i++) {
if (i % 3 == nPos && i != 0)
*wsOutput += wsGroupSymbol;
*wsOutput += wsSrcNum[i];
}
- if (dot_index < len) {
+ if (pdfium::base::checked_cast<int32_t>(dot_index.value()) < len) {
*wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal);
*wsOutput += wsSrcNum.Right(len - dot_index.value() - 1);
}
@@ -2102,7 +2105,8 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
}
return false;
}
- if (dot_index_f == wsNumFormat.GetLength()) {
+ if (dot_index_f ==
+ pdfium::base::checked_cast<int32_t>(wsNumFormat.GetLength())) {
if (!bAddNeg && bNeg) {
*wsOutput =
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + *wsOutput;
@@ -2115,7 +2119,7 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
if (strf[dot_index_f] == 'V') {
*wsOutput += wsDotSymbol;
} else if (strf[dot_index_f] == '.') {
- if (dot_index < len)
+ if (pdfium::base::checked_cast<int32_t>(dot_index.value()) < len)
*wsOutput += wsDotSymbol;
else if (strf[dot_index_f + 1] == '9' || strf[dot_index_f + 1] == 'Z')
*wsOutput += wsDotSymbol;
diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp
index c465c96ff0..58ddbac806 100644
--- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp
@@ -66,7 +66,7 @@ TEST(FMStringExpressionTest, Long) {
CFX_WideTextBuf accumulator;
std::vector<CFX_WideStringC::UnsignedType> vec(140000, L'A');
CXFA_FMStringExpression(1, CFX_WideStringC(vec)).ToJavaScript(accumulator);
- EXPECT_EQ(140000, accumulator.GetLength());
+ EXPECT_EQ(140000u, accumulator.GetLength());
}
TEST(FMStringExpressionTest, Quoted) {
diff --git a/xfa/fxfa/parser/cxfa_scriptcontext.cpp b/xfa/fxfa/parser/cxfa_scriptcontext.cpp
index e7c86296ee..98b5da057f 100644
--- a/xfa/fxfa/parser/cxfa_scriptcontext.cpp
+++ b/xfa/fxfa/parser/cxfa_scriptcontext.cpp
@@ -624,7 +624,9 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refObject,
bool bCreate =
m_ResolveProcessor->GetNodeHelper()->ResolveNodes_CreateNode(
rndFind.m_wsName, rndFind.m_wsCondition,
- nStart == wsExpression.GetLength(), this);
+ nStart ==
+ pdfium::base::checked_cast<int32_t>(wsExpression.GetLength()),
+ this);
if (bCreate) {
continue;
} else {
@@ -650,7 +652,9 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refObject,
continue;
}
if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute &&
- rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) {
+ rndFind.m_pScriptAttribute &&
+ nStart <
+ pdfium::base::checked_cast<int32_t>(wsExpression.GetLength())) {
auto pValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
(rndFind.m_Objects.front()
->*(rndFind.m_pScriptAttribute->lpfnCallback))(
@@ -679,7 +683,9 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refObject,
bool bCreate =
m_ResolveProcessor->GetNodeHelper()->ResolveNodes_CreateNode(
rndFind.m_wsName, rndFind.m_wsCondition,
- nStart == wsExpression.GetLength(), this);
+ nStart == pdfium::base::checked_cast<int32_t>(
+ wsExpression.GetLength()),
+ this);
if (bCreate) {
continue;
} else {