From aa3a9cd82df9dff1ef136797259e606a39c18b75 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Tue, 29 Aug 2017 16:39:44 -0400 Subject: Convert int* references to FX_STRSIZE Through out the code base there are numerous places where variables are declared using a signed integer type when interacting with the string classes, since they assume that FX_STRSIZE is 'int'. As part of changing the underling type of FX_STRSIZE to be unsigned, these locations are being changed to use FX_STRSIZE. This is necessary as part of converting the type, but has been broken off into a separate CL, since it should be low risk. Some related cleanups that are low risk are included as part of this CL. BUG=pdfium:828 Change-Id: Ifaae54ad195ccde0fe8672f71271d29a6ebd65fd Reviewed-on: https://pdfium-review.googlesource.com/12210 Reviewed-by: Tom Sepez Reviewed-by: Henrique Nakashima Reviewed-by: dsinclair Commit-Queue: Ryan Harrison --- core/fxcrt/cfx_bytestring.cpp | 2 +- core/fxcrt/cfx_chariter.cpp | 7 ++++--- core/fxcrt/cfx_seekablestreamproxy.cpp | 4 ++-- core/fxcrt/cfx_string_data_template.h | 6 +++--- core/fxcrt/fx_basic.h | 2 +- core/fxcrt/fx_basic_buffer.cpp | 2 +- core/fxcrt/fx_basic_util.cpp | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) (limited to 'core/fxcrt') diff --git a/core/fxcrt/cfx_bytestring.cpp b/core/fxcrt/cfx_bytestring.cpp index ac390949ee..13b6673c70 100644 --- a/core/fxcrt/cfx_bytestring.cpp +++ b/core/fxcrt/cfx_bytestring.cpp @@ -427,7 +427,7 @@ FX_STRSIZE CFX_ByteString::Delete(FX_STRSIZE index, FX_STRSIZE count) { return old_length; ReallocBeforeWrite(old_length); - int chars_to_copy = old_length - removal_length + 1; + FX_STRSIZE chars_to_copy = old_length - removal_length + 1; memmove(m_pData->m_String + index, m_pData->m_String + removal_length, chars_to_copy); m_pData->m_nDataLength = old_length - count; diff --git a/core/fxcrt/cfx_chariter.cpp b/core/fxcrt/cfx_chariter.cpp index db94fb09f4..827e86967d 100644 --- a/core/fxcrt/cfx_chariter.cpp +++ b/core/fxcrt/cfx_chariter.cpp @@ -21,7 +21,7 @@ bool CFX_CharIter::Next(bool bPrev) { return false; m_nIndex--; } else { - if (m_nIndex + 1 >= m_wsText.GetLength()) + if (static_cast(m_nIndex + 1) >= m_wsText.GetLength()) return false; m_nIndex++; } @@ -33,7 +33,7 @@ wchar_t CFX_CharIter::GetChar() const { } void CFX_CharIter::SetAt(int32_t nIndex) { - if (nIndex < 0 || nIndex >= m_wsText.GetLength()) + if (nIndex < 0 || static_cast(nIndex) >= m_wsText.GetLength()) return; m_nIndex = nIndex; } @@ -43,7 +43,8 @@ int32_t CFX_CharIter::GetAt() const { } bool CFX_CharIter::IsEOF(bool bTail) const { - return bTail ? (m_nIndex + 1 == m_wsText.GetLength()) : (m_nIndex == 0); + return bTail ? (static_cast(m_nIndex + 1) == m_wsText.GetLength()) + : (m_nIndex == 0); } std::unique_ptr CFX_CharIter::Clone() const { diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp index e610e0a9c3..da1170717a 100644 --- a/core/fxcrt/cfx_seekablestreamproxy.cpp +++ b/core/fxcrt/cfx_seekablestreamproxy.cpp @@ -98,8 +98,8 @@ void UTF16ToWChar(void* pBuffer, FX_STRSIZE iLength) { uint16_t* pSrc = static_cast(pBuffer); wchar_t* pDst = static_cast(pBuffer); - while (--iLength >= 0) - pDst[iLength] = static_cast(pSrc[iLength]); + for (FX_STRSIZE i = 0; i < iLength; i++) + pDst[i] = static_cast(pSrc[i]); } void SwapByteOrder(wchar_t* pStr, FX_STRSIZE iLength) { diff --git a/core/fxcrt/cfx_string_data_template.h b/core/fxcrt/cfx_string_data_template.h index e39f6a5dfd..eabb608818 100644 --- a/core/fxcrt/cfx_string_data_template.h +++ b/core/fxcrt/cfx_string_data_template.h @@ -21,7 +21,7 @@ class CFX_StringDataTemplate { // NUL char that is not included in |m_nAllocLength|. int overhead = offsetof(CFX_StringDataTemplate, m_String) + sizeof(CharType); - pdfium::base::CheckedNumeric nSize = nLen; + pdfium::base::CheckedNumeric nSize = nLen; nSize *= sizeof(CharType); nSize += overhead; @@ -31,8 +31,8 @@ class CFX_StringDataTemplate { // by using this otherwise wasted space. nSize += 7; nSize &= ~7; - int totalSize = nSize.ValueOrDie(); - int usableLen = (totalSize - overhead) / sizeof(CharType); + FX_STRSIZE totalSize = nSize.ValueOrDie(); + FX_STRSIZE usableLen = (totalSize - overhead) / sizeof(CharType); ASSERT(usableLen >= nLen); void* pData = pdfium::base::PartitionAllocGeneric( diff --git a/core/fxcrt/fx_basic.h b/core/fxcrt/fx_basic.h index 47cce9a60f..1f05dfb627 100644 --- a/core/fxcrt/fx_basic.h +++ b/core/fxcrt/fx_basic.h @@ -43,7 +43,7 @@ class CFX_BinaryBuf { } void InsertBlock(FX_STRSIZE pos, const void* pBuf, FX_STRSIZE size); - void Delete(int start_index, int count); + void Delete(FX_STRSIZE start_index, FX_STRSIZE count); // Releases ownership of |m_pBuffer| and returns it. std::unique_ptr DetachBuffer(); diff --git a/core/fxcrt/fx_basic_buffer.cpp b/core/fxcrt/fx_basic_buffer.cpp index a359bdd5d0..310aec7faf 100644 --- a/core/fxcrt/fx_basic_buffer.cpp +++ b/core/fxcrt/fx_basic_buffer.cpp @@ -23,7 +23,7 @@ CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size) CFX_BinaryBuf::~CFX_BinaryBuf() {} -void CFX_BinaryBuf::Delete(int start_index, int count) { +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) { return; diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp index 05ab20472c..6f59f32fff 100644 --- a/core/fxcrt/fx_basic_util.cpp +++ b/core/fxcrt/fx_basic_util.cpp @@ -28,7 +28,7 @@ bool FX_atonum(const CFX_ByteStringC& strc, void* pData) { pdfium::base::CheckedNumeric integer = 0; bool bNegative = false; bool bSigned = false; - int cc = 0; + FX_STRSIZE cc = 0; if (strc[0] == '+') { cc++; bSigned = true; -- cgit v1.2.3