Replace a #define in progressivedecoder.cpp.
Replace |FXCODEC_BLOCK_SIZE| with |kBlockSize|. Also use std::min() in
several places where |kBlockSize| is used.
Change-Id: I74d422f5758e85cdd30cc8c2fc695c0896b5004f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/57852
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcodec/progressivedecoder.cpp b/core/fxcodec/progressivedecoder.cpp
index 0271a8d..88a22da 100644
--- a/core/fxcodec/progressivedecoder.cpp
+++ b/core/fxcodec/progressivedecoder.cpp
@@ -23,12 +23,12 @@
#include "third_party/base/numerics/safe_math.h"
#include "third_party/base/ptr_util.h"
-#define FXCODEC_BLOCK_SIZE 4096
-
namespace fxcodec {
namespace {
+constexpr size_t kBlockSize = 4096;
+
#ifdef PDF_ENABLE_XFA_PNG
#if defined(OS_MACOSX)
const double kPngGamma = 1.7;
@@ -1235,8 +1235,7 @@
}
while (pPngModule->Input(m_pPngContext.get(), m_pCodecMemory, pAttribute)) {
uint32_t remain_size = static_cast<uint32_t>(m_pFile->GetSize()) - m_offSet;
- uint32_t input_size =
- remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size;
+ uint32_t input_size = std::min<uint32_t>(remain_size, kBlockSize);
if (input_size == 0) {
m_pPngContext.reset();
m_status = FXCODEC_STATUS_ERR_FORMAT;
@@ -1316,8 +1315,7 @@
}
while (true) {
uint32_t remain_size = (uint32_t)m_pFile->GetSize() - m_offSet;
- uint32_t input_size =
- remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size;
+ uint32_t input_size = std::min<uint32_t>(remain_size, kBlockSize);
if (input_size == 0) {
m_pPngContext.reset();
m_pDeviceBitmap = nullptr;
@@ -1525,7 +1523,7 @@
return TiffDetectImageTypeFromFile(pAttribute);
#endif // PDF_ENABLE_XFA_TIFF
- size_t size = std::min<size_t>(m_pFile->GetSize(), FXCODEC_BLOCK_SIZE);
+ size_t size = std::min<size_t>(m_pFile->GetSize(), kBlockSize);
m_pCodecMemory = pdfium::MakeRetain<CFX_CodecMemory>(size);
m_offSet = 0;
if (!m_pFile->ReadBlockAtOffset(m_pCodecMemory->GetBuffer(), m_offSet,
@@ -1582,7 +1580,7 @@
// Increase the buffer size so that there might be enough contiguous
// bytes to allow whatever operation is having difficulty to succeed.
dwBytesToFetchFromFile =
- std::min<uint32_t>(dwBytesToFetchFromFile, FXCODEC_BLOCK_SIZE);
+ std::min<uint32_t>(dwBytesToFetchFromFile, kBlockSize);
size_t dwNewSize = m_pCodecMemory->GetSize() + dwBytesToFetchFromFile;
if (!m_pCodecMemory->TryResize(dwNewSize)) {
err_status = FXCODEC_STATUS_ERR_MEMORY;