From 4e597c8fd5d604273266ea19a1074a2c870ba224 Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 7 Nov 2016 15:16:01 -0800 Subject: Force compiler to deduce src type for checked_cast. Otherwise, we might be silently doing an unsafe cast before applying the check if the actual argument doesn't match the exact src type. Review-Url: https://codereview.chromium.org/2484953003 --- core/fpdfapi/parser/cpdf_parser.cpp | 6 ++---- core/fpdfdoc/cpdf_formfield.cpp | 2 +- fpdfsdk/fpdfview.cpp | 6 ++---- third_party/base/stl_util.h | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp index cf23ec7cd7..ed20cf73f4 100644 --- a/core/fpdfapi/parser/cpdf_parser.cpp +++ b/core/fpdfapi/parser/cpdf_parser.cpp @@ -1015,10 +1015,8 @@ bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) { if (startnum < 0) continue; - m_dwXrefStartObjNum = - pdfium::base::checked_cast(startnum); - uint32_t count = - pdfium::base::checked_cast(arrIndex[i].second); + m_dwXrefStartObjNum = pdfium::base::checked_cast(startnum); + uint32_t count = pdfium::base::checked_cast(arrIndex[i].second); FX_SAFE_UINT32 dwCaculatedSize = segindex; dwCaculatedSize += count; dwCaculatedSize *= totalWidth; diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp index e2240c9f2f..8170b7fcbf 100644 --- a/core/fpdfdoc/cpdf_formfield.cpp +++ b/core/fpdfdoc/cpdf_formfield.cpp @@ -682,7 +682,7 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, m_pDict->SetFor("Opt", pOpt); } - int iCount = pdfium::base::checked_cast(pOpt->GetCount()); + int iCount = pdfium::base::checked_cast(pOpt->GetCount()); if (index >= iCount) { pOpt->AddString(csStr); index = iCount; diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index 9142dc78c9..334c14cd45 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -192,8 +192,7 @@ bool CPDF_CustomAccess::ReadBlock(void* buffer, if (offset < 0) return false; - FX_SAFE_FILESIZE newPos = - pdfium::base::checked_cast(size); + FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast(size); newPos += offset; if (!newPos.IsValid() || newPos.ValueOrDie() > static_cast(m_FileAccess.m_FileLen)) { @@ -388,8 +387,7 @@ class CMemFile final : public IFX_SeekableReadStream { if (offset < 0) { return false; } - FX_SAFE_FILESIZE newPos = - pdfium::base::checked_cast(size); + FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast(size); newPos += offset; if (!newPos.IsValid() || newPos.ValueOrDie() > m_size) { return false; diff --git a/third_party/base/stl_util.h b/third_party/base/stl_util.h index 0bf442c316..795414b59f 100644 --- a/third_party/base/stl_util.h +++ b/third_party/base/stl_util.h @@ -41,7 +41,7 @@ class FakeUniquePtr : public std::unique_ptr { // size_t size() method return values will be checked. template ResultType CollectionSize(const Collection& collection) { - return pdfium::base::checked_cast(collection.size()); + return pdfium::base::checked_cast(collection.size()); } // Track the addition of an object to a set, removing it automatically when -- cgit v1.2.3