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

Side by Side Diff: pdf/pdfium/pdfium_api_string_buffer_adapter.h

Issue 2543443003: Fix pdfium use of base/numerics (Closed)
Patch Set: Created 4 years 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium 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 #ifndef PDF_PDFIUM_PDFIUM_API_STRING_BUFFER_ADAPTER_H_ 5 #ifndef PDF_PDFIUM_PDFIUM_API_STRING_BUFFER_ADAPTER_H_
6 #define PDF_PDFIUM_PDFIUM_API_STRING_BUFFER_ADAPTER_H_ 6 #define PDF_PDFIUM_PDFIUM_API_STRING_BUFFER_ADAPTER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 24 matching lines...) Expand all
35 // pointer has space to write a null-terminator. 35 // pointer has space to write a null-terminator.
36 void* GetData(); 36 void* GetData();
37 37
38 // Resizes |str_| to |actual_size| - 1 characters, thereby removing the extra 38 // Resizes |str_| to |actual_size| - 1 characters, thereby removing the extra
39 // null-terminator. This must be called prior to the adapter's destruction. 39 // null-terminator. This must be called prior to the adapter's destruction.
40 // The pointer returned by GetData() should be considered invalid. 40 // The pointer returned by GetData() should be considered invalid.
41 void Close(size_t actual_size); 41 void Close(size_t actual_size);
42 42
43 template <typename IntType> 43 template <typename IntType>
44 void Close(IntType actual_size) { 44 void Close(IntType actual_size) {
45 base::CheckedNumeric<size_t> unsigned_size = actual_size; 45 Close(base::checked_cast<size_t>(actual_size));
46 Close(unsigned_size.ValueOrDie());
47 } 46 }
48 47
49 private: 48 private:
50 StringType* const str_; 49 StringType* const str_;
51 void* const data_; 50 void* const data_;
52 const size_t expected_size_; 51 const size_t expected_size_;
53 const bool check_expected_size_; 52 const bool check_expected_size_;
54 bool is_closed_; 53 bool is_closed_;
55 54
56 DISALLOW_COPY_AND_ASSIGN(PDFiumAPIStringBufferAdapter); 55 DISALLOW_COPY_AND_ASSIGN(PDFiumAPIStringBufferAdapter);
(...skipping 24 matching lines...) Expand all
81 void* GetData(); 80 void* GetData();
82 81
83 // Resizes |str_| to |actual_size| - sizeof(StringType::value_type) bytes, 82 // Resizes |str_| to |actual_size| - sizeof(StringType::value_type) bytes,
84 // thereby removing the extra null-terminator. This must be called prior to 83 // thereby removing the extra null-terminator. This must be called prior to
85 // the adapter's destruction. The pointer returned by GetData() should be 84 // the adapter's destruction. The pointer returned by GetData() should be
86 // considered invalid. 85 // considered invalid.
87 void Close(size_t actual_size); 86 void Close(size_t actual_size);
88 87
89 template <typename IntType> 88 template <typename IntType>
90 void Close(IntType actual_size) { 89 void Close(IntType actual_size) {
91 base::CheckedNumeric<size_t> unsigned_size = actual_size; 90 Close(base::checked_cast<size_t>(actual_size));
92 Close(unsigned_size.ValueOrDie());
93 } 91 }
94 92
95 private: 93 private:
96 PDFiumAPIStringBufferAdapter<StringType> adapter_; 94 PDFiumAPIStringBufferAdapter<StringType> adapter_;
97 }; 95 };
98 96
99 } // namespace chrome_pdf 97 } // namespace chrome_pdf
100 98
101 #endif // PDF_PDFIUM_PDFIUM_API_STRING_BUFFER_ADAPTER_H_ 99 #endif // PDF_PDFIUM_PDFIUM_API_STRING_BUFFER_ADAPTER_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698