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

Side by Side Diff: fpdfsdk/fpdfview.cpp

Issue 2484953003: Force compiler to deduce src type for checked_cast<dst, src>. (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « core/fpdfdoc/cpdf_formfield.cpp ('k') | third_party/base/stl_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "public/fpdfview.h" 7 #include "public/fpdfview.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 void CPDF_CustomAccess::Release() { 185 void CPDF_CustomAccess::Release() {
186 delete this; 186 delete this;
187 } 187 }
188 188
189 bool CPDF_CustomAccess::ReadBlock(void* buffer, 189 bool CPDF_CustomAccess::ReadBlock(void* buffer,
190 FX_FILESIZE offset, 190 FX_FILESIZE offset,
191 size_t size) { 191 size_t size) {
192 if (offset < 0) 192 if (offset < 0)
193 return false; 193 return false;
194 194
195 FX_SAFE_FILESIZE newPos = 195 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size);
196 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size);
197 newPos += offset; 196 newPos += offset;
198 if (!newPos.IsValid() || 197 if (!newPos.IsValid() ||
199 newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) { 198 newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) {
200 return false; 199 return false;
201 } 200 }
202 return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, 201 return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,
203 reinterpret_cast<uint8_t*>(buffer), size); 202 reinterpret_cast<uint8_t*>(buffer), size);
204 } 203 }
205 204
206 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS 205 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 class CMemFile final : public IFX_SeekableReadStream { 380 class CMemFile final : public IFX_SeekableReadStream {
382 public: 381 public:
383 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {} 382 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {}
384 383
385 void Release() override { delete this; } 384 void Release() override { delete this; }
386 FX_FILESIZE GetSize() override { return m_size; } 385 FX_FILESIZE GetSize() override { return m_size; }
387 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { 386 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
388 if (offset < 0) { 387 if (offset < 0) {
389 return false; 388 return false;
390 } 389 }
391 FX_SAFE_FILESIZE newPos = 390 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size);
392 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size);
393 newPos += offset; 391 newPos += offset;
394 if (!newPos.IsValid() || newPos.ValueOrDie() > m_size) { 392 if (!newPos.IsValid() || newPos.ValueOrDie() > m_size) {
395 return false; 393 return false;
396 } 394 }
397 FXSYS_memcpy(buffer, m_pBuf + offset, size); 395 FXSYS_memcpy(buffer, m_pBuf + offset, size);
398 return true; 396 return true;
399 } 397 }
400 398
401 private: 399 private:
402 ~CMemFile() override {} 400 ~CMemFile() override {}
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 if (!buffer) { 1108 if (!buffer) {
1111 *buflen = len; 1109 *buflen = len;
1112 } else if (*buflen >= len) { 1110 } else if (*buflen >= len) {
1113 memcpy(buffer, utf16Name.c_str(), len); 1111 memcpy(buffer, utf16Name.c_str(), len);
1114 *buflen = len; 1112 *buflen = len;
1115 } else { 1113 } else {
1116 *buflen = -1; 1114 *buflen = -1;
1117 } 1115 }
1118 return (FPDF_DEST)pDestObj; 1116 return (FPDF_DEST)pDestObj;
1119 } 1117 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_formfield.cpp ('k') | third_party/base/stl_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698