Use size_t for lengths in WideString, part 1
Fix easy conversions flagged by -Wshorten-64-to-32
Change-Id: I6ad6b02810488b317fcb4c12890dcbcca6531068
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/86898
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/widestring.cpp b/core/fxcrt/widestring.cpp
index f3a4b3e3..99f56b2 100644
--- a/core/fxcrt/widestring.cpp
+++ b/core/fxcrt/widestring.cpp
@@ -35,23 +35,22 @@
constexpr wchar_t kWideTrimChars[] = L"\x09\x0a\x0b\x0c\x0d\x20";
const wchar_t* FX_wcsstr(const wchar_t* haystack,
- int haystack_len,
+ size_t haystack_len,
const wchar_t* needle,
- int needle_len) {
- if (needle_len > haystack_len || needle_len == 0) {
+ size_t needle_len) {
+ if (needle_len > haystack_len || needle_len == 0)
return nullptr;
- }
+
const wchar_t* end_ptr = haystack + haystack_len - needle_len;
while (haystack <= end_ptr) {
- int i = 0;
+ size_t i = 0;
while (1) {
- if (haystack[i] != needle[i]) {
+ if (haystack[i] != needle[i])
break;
- }
+
i++;
- if (i == needle_len) {
+ if (i == needle_len)
return haystack;
- }
}
haystack++;
}
@@ -679,11 +678,11 @@
return ByteString("\0\0", 2);
ByteString result;
- int len = m_pData->m_nDataLength;
+ size_t len = m_pData->m_nDataLength;
{
// Span's lifetime must end before ReleaseBuffer() below.
pdfium::span<char> buffer = result.GetBuffer(len * 2 + 2);
- for (int i = 0; i < len; i++) {
+ for (size_t i = 0; i < len; i++) {
buffer[i * 2] = m_pData->m_String[i] & 0xff;
buffer[i * 2 + 1] = m_pData->m_String[i] >> 8;
}