Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: core/fxcrt/fx_extension.cpp

Issue 2430743003: in the attempt to fix 627393, changed IFX_FileRead's readBlock to return the length it reads
Patch Set: fix an undefined variable Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/fxcrt/fx_extension.cpp
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index 0a378f32e5ffaf73184047de79539314064f81f9..4768b1b2f946ac868712127e4c738cd43322a640 100644
--- a/core/fxcrt/fx_extension.cpp
+++ b/core/fxcrt/fx_extension.cpp
@@ -104,31 +104,32 @@ FX_FILESIZE CFX_MemoryStream::GetSize() {
}
bool CFX_MemoryStream::IsEOF() {
- return m_nCurPos >= (size_t)GetSize();
+ return m_nCurPos >= pdfium::base::checked_cast<size_t>(GetSize());
}
FX_FILESIZE CFX_MemoryStream::GetPosition() {
return (FX_FILESIZE)m_nCurPos;
}
-bool CFX_MemoryStream::ReadBlock(void* buffer,
- FX_FILESIZE offset,
- size_t size) {
+size_t CFX_MemoryStream::ReadBlock(void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
if (!buffer || !size)
- return false;
+ return 0;
FX_SAFE_SIZE_T newPos = size;
newPos += offset;
if (!newPos.IsValid() || newPos.ValueOrDefault(0) == 0 ||
newPos.ValueOrDie() > m_nCurSize) {
- return false;
+ return 0;
}
m_nCurPos = newPos.ValueOrDie();
if (m_dwFlags & FX_MEMSTREAM_Consecutive) {
FXSYS_memcpy(buffer, m_Blocks[0] + (size_t)offset, size);
- return true;
+ return size;
}
+ size_t readSize = size;
size_t nStartBlock = (size_t)offset / m_nGrowSize;
offset -= (FX_FILESIZE)(nStartBlock * m_nGrowSize);
while (size) {
@@ -142,7 +143,7 @@ bool CFX_MemoryStream::ReadBlock(void* buffer,
nStartBlock++;
offset = 0;
}
- return true;
+ return readSize;
}
size_t CFX_MemoryStream::ReadBlock(void* buffer, size_t size) {
@@ -150,7 +151,7 @@ size_t CFX_MemoryStream::ReadBlock(void* buffer, size_t size) {
return 0;
}
size_t nRead = std::min(size, m_nCurSize - m_nCurPos);
- if (!ReadBlock(buffer, (int32_t)m_nCurPos, nRead)) {
+ if (ReadBlock(buffer, (int32_t)m_nCurPos, nRead) != nRead && !IsEOF()) {
return 0;
}
return nRead;
@@ -305,10 +306,10 @@ FX_FILESIZE CFX_CRTFileStream::GetPosition() {
return m_pFile->GetPosition();
}
-bool CFX_CRTFileStream::ReadBlock(void* buffer,
- FX_FILESIZE offset,
- size_t size) {
- return m_pFile->ReadPos(buffer, size, offset) > 0;
+size_t CFX_CRTFileStream::ReadBlock(void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
+ return m_pFile->ReadPos(buffer, size, offset);
}
size_t CFX_CRTFileStream::ReadBlock(void* buffer, size_t size) {

Powered by Google App Engine
This is Rietveld 408576698