From 81f9eeef041f2974274751d7508598049ae32db2 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Tue, 5 Sep 2017 15:33:18 -0400 Subject: 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 Reviewed-by: Tom Sepez Commit-Queue: Ryan Harrison --- core/fxcrt/cfx_string_c_template.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'core/fxcrt/cfx_string_c_template.h') 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(ptr)), - m_Length(len < 0 ? FXSYS_len(ptr) : len) {} + : m_Ptr(reinterpret_cast(ptr)), m_Length(len) {} template 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(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)); -- cgit v1.2.3