Fix remaining -Wshorten-64-to-32 warnings for fxcrt.
We will add the flag itself in a subsequent standalone CL.
Change-Id: I832880b4787ff1fc82e63426752066a484219090
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/88310
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/cfx_fileaccess_posix.cpp b/core/fxcrt/cfx_fileaccess_posix.cpp
index bf6c1b3..f558282 100644
--- a/core/fxcrt/cfx_fileaccess_posix.cpp
+++ b/core/fxcrt/cfx_fileaccess_posix.cpp
@@ -13,6 +13,7 @@
#include <memory>
#include "core/fxcrt/fx_stream.h"
+#include "third_party/base/numerics/safe_conversions.h"
#ifndef O_BINARY
#define O_BINARY 0
@@ -82,7 +83,7 @@
struct stat s;
memset(&s, 0, sizeof(s));
fstat(m_nFD, &s);
- return s.st_size;
+ return pdfium::base::checked_cast<FX_FILESIZE>(s.st_size);
}
FX_FILESIZE CFX_FileAccess_Posix::GetPosition() const {
if (m_nFD < 0) {
diff --git a/core/fxcrt/cfx_readonlymemorystream.cpp b/core/fxcrt/cfx_readonlymemorystream.cpp
index 807788a..676dae9 100644
--- a/core/fxcrt/cfx_readonlymemorystream.cpp
+++ b/core/fxcrt/cfx_readonlymemorystream.cpp
@@ -9,6 +9,7 @@
#include <utility>
#include "core/fxcrt/fx_safe_types.h"
+#include "third_party/base/numerics/safe_conversions.h"
CFX_ReadOnlyMemoryStream::CFX_ReadOnlyMemoryStream(
std::unique_ptr<uint8_t, FxFreeDeleter> data,
@@ -36,7 +37,8 @@
if (!pos.IsValid() || pos.ValueOrDie() > m_span.size())
return false;
- auto copy_span = m_span.subspan(offset, size);
+ auto copy_span =
+ m_span.subspan(pdfium::base::checked_cast<size_t>(offset), size);
memcpy(buffer, copy_span.data(), copy_span.size());
return true;
}
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp
index 6b324f0..80432e0 100644
--- a/core/fxcrt/xml/cfx_xmlparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -95,8 +95,8 @@
if (!alloc_size_safe.IsValid())
return false;
- FX_FILESIZE current_buffer_idx = 0;
- FX_FILESIZE buffer_size = 0;
+ size_t current_buffer_idx = 0;
+ size_t buffer_size = 0;
std::vector<wchar_t, FxAllocAllocator<wchar_t>> buffer;
buffer.resize(alloc_size_safe.ValueOrDie());