diff options
author | Ryan Harrison <rharrison@chromium.org> | 2017-09-05 15:33:18 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-09-06 13:53:19 +0000 |
commit | 81f9eeef041f2974274751d7508598049ae32db2 (patch) | |
tree | 00bdcdddc9d141e4929005a14372bde65c68ee81 /core | |
parent | 3ef61c73a97b31000a21e323e04ad5397e517c4c (diff) | |
download | pdfium-81f9eeef041f2974274751d7508598049ae32db2.tar.xz |
Convert FX_STRSIZE int->size_t
Change the underlying type for FX_STRSIZE to size_t from int. This
will make the value unsigned and thus all values in the range of the
type will be valid. This allows for the final remove of negative
length strings, but also introduces a some casting and functional
errors, since many parts of the code base assume that FX_STRSIZE is
int or another signed type. This also CL fixes these errors.
BUG=pdfium:828
Change-Id: I231dca59e96fc9330cbb099eecbdfc41fcf86f5b
Reviewed-on: https://pdfium-review.googlesource.com/11830
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/font/cpdf_cmapparser_unittest.cpp | 8 | ||||
-rw-r--r-- | core/fxcrt/cfx_binarybuf.cpp | 5 | ||||
-rw-r--r-- | core/fxcrt/cfx_bytestring.cpp | 30 | ||||
-rw-r--r-- | core/fxcrt/cfx_bytestring.h | 10 | ||||
-rw-r--r-- | core/fxcrt/cfx_bytestring_unittest.cpp | 134 | ||||
-rw-r--r-- | core/fxcrt/cfx_seekablestreamproxy.cpp | 5 | ||||
-rw-r--r-- | core/fxcrt/cfx_string_c_template.h | 16 | ||||
-rw-r--r-- | core/fxcrt/cfx_widestring.cpp | 37 | ||||
-rw-r--r-- | core/fxcrt/cfx_widestring.h | 10 | ||||
-rw-r--r-- | core/fxcrt/cfx_widestring_unittest.cpp | 110 | ||||
-rw-r--r-- | core/fxcrt/fx_system.h | 7 |
11 files changed, 169 insertions, 203 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 |