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

Side by Side Diff: third_party/WebKit/Source/platform/wtf/TerminatedArray.h

Issue 2957583004: Check for integer overflow in allocations. (Closed)
Patch Set: Rename the function to |ComputeAllocationSize|. Created 3 years, 5 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef TerminatedArray_h 4 #ifndef TerminatedArray_h
5 #define TerminatedArray_h 5 #define TerminatedArray_h
6 6
7 #include "platform/wtf/Allocator.h" 7 #include "platform/wtf/Allocator.h"
8 #include "platform/wtf/PtrUtil.h" 8 #include "platform/wtf/PtrUtil.h"
9 #include "platform/wtf/VectorTraits.h" 9 #include "platform/wtf/VectorTraits.h"
10 #include "platform/wtf/allocator/Partitions.h" 10 #include "platform/wtf/allocator/Partitions.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 struct Allocator { 91 struct Allocator {
92 STATIC_ONLY(Allocator); 92 STATIC_ONLY(Allocator);
93 using PassPtr = std::unique_ptr<TerminatedArray>; 93 using PassPtr = std::unique_ptr<TerminatedArray>;
94 using Ptr = std::unique_ptr<TerminatedArray>; 94 using Ptr = std::unique_ptr<TerminatedArray>;
95 95
96 static PassPtr Release(Ptr& ptr) { return ptr.release(); } 96 static PassPtr Release(Ptr& ptr) { return ptr.release(); }
97 97
98 static PassPtr Create(size_t capacity) { 98 static PassPtr Create(size_t capacity) {
99 return WTF::WrapUnique( 99 return WTF::WrapUnique(
100 static_cast<TerminatedArray*>(WTF::Partitions::FastMalloc( 100 static_cast<TerminatedArray*>(WTF::Partitions::FastMalloc(
101 capacity * sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T)))); 101 WTF::Partitions::ComputeAllocationSize(capacity, sizeof(T)),
102 WTF_HEAP_PROFILER_TYPE_NAME(T))));
102 } 103 }
103 104
104 static PassPtr Resize(Ptr ptr, size_t capacity) { 105 static PassPtr Resize(Ptr ptr, size_t capacity) {
105 return WTF::WrapUnique(static_cast<TerminatedArray*>( 106 return WTF::WrapUnique(
106 WTF::Partitions::FastRealloc(ptr.release(), capacity * sizeof(T), 107 static_cast<TerminatedArray*>(WTF::Partitions::FastRealloc(
107 WTF_HEAP_PROFILER_TYPE_NAME(T)))); 108 ptr.release(),
109 WTF::Partitions::ComputeAllocationSize(capacity, sizeof(T)),
110 WTF_HEAP_PROFILER_TYPE_NAME(T))));
108 } 111 }
109 }; 112 };
110 113
111 // Prohibit construction. Allocator makes TerminatedArray instances for 114 // Prohibit construction. Allocator makes TerminatedArray instances for
112 // TerminatedArrayBuilder by pointer casting. 115 // TerminatedArrayBuilder by pointer casting.
113 TerminatedArray(); 116 TerminatedArray();
114 117
115 template <typename, template <typename> class> 118 template <typename, template <typename> class>
116 friend class TerminatedArrayBuilder; 119 friend class TerminatedArrayBuilder;
117 }; 120 };
118 121
119 } // namespace WTF 122 } // namespace WTF
120 123
121 using WTF::TerminatedArray; 124 using WTF::TerminatedArray;
122 125
123 #endif // TerminatedArray_h 126 #endif // TerminatedArray_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698