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

Side by Side Diff: third_party/WebKit/Source/platform/heap/HeapTerminatedArray.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 4
5 #ifndef HeapTerminatedArray_h 5 #ifndef HeapTerminatedArray_h
6 #define HeapTerminatedArray_h 6 #define HeapTerminatedArray_h
7 7
8 #include "platform/heap/Heap.h" 8 #include "platform/heap/Heap.h"
9 #include "platform/wtf/TerminatedArray.h" 9 #include "platform/wtf/TerminatedArray.h"
10 #include "platform/wtf/TerminatedArrayBuilder.h" 10 #include "platform/wtf/TerminatedArrayBuilder.h"
11 #include "platform/wtf/allocator/Partitions.h"
11 12
12 namespace blink { 13 namespace blink {
13 14
14 template <typename T> 15 template <typename T>
15 class HeapTerminatedArray : public TerminatedArray<T> { 16 class HeapTerminatedArray : public TerminatedArray<T> {
16 DISALLOW_NEW(); 17 DISALLOW_NEW();
17 IS_GARBAGE_COLLECTED_TYPE(); 18 IS_GARBAGE_COLLECTED_TYPE();
18 19
19 public: 20 public:
20 using TerminatedArray<T>::begin; 21 using TerminatedArray<T>::begin;
(...skipping 10 matching lines...) Expand all
31 struct Allocator final { 32 struct Allocator final {
32 STATIC_ONLY(Allocator); 33 STATIC_ONLY(Allocator);
33 using PassPtr = HeapTerminatedArray*; 34 using PassPtr = HeapTerminatedArray*;
34 using Ptr = Member<HeapTerminatedArray>; 35 using Ptr = Member<HeapTerminatedArray>;
35 36
36 static PassPtr Release(Ptr& ptr) { return ptr; } 37 static PassPtr Release(Ptr& ptr) { return ptr; }
37 38
38 static PassPtr Create(size_t capacity) { 39 static PassPtr Create(size_t capacity) {
39 return reinterpret_cast<HeapTerminatedArray*>( 40 return reinterpret_cast<HeapTerminatedArray*>(
40 ThreadHeap::Allocate<HeapTerminatedArray>( 41 ThreadHeap::Allocate<HeapTerminatedArray>(
41 capacity * sizeof(T), IsEagerlyFinalizedType<T>::value)); 42 WTF::Partitions::ComputeAllocationSize(capacity, sizeof(T)),
43 IsEagerlyFinalizedType<T>::value));
42 } 44 }
43 45
44 static PassPtr Resize(PassPtr ptr, size_t capacity) { 46 static PassPtr Resize(PassPtr ptr, size_t capacity) {
45 return reinterpret_cast<HeapTerminatedArray*>( 47 return reinterpret_cast<HeapTerminatedArray*>(
46 ThreadHeap::Reallocate<HeapTerminatedArray>(ptr, 48 ThreadHeap::Reallocate<HeapTerminatedArray>(
47 capacity * sizeof(T))); 49 ptr,
50 WTF::Partitions::ComputeAllocationSize(capacity, sizeof(T))));
48 } 51 }
49 }; 52 };
50 53
51 // Prohibit construction. Allocator makes HeapTerminatedArray instances for 54 // Prohibit construction. Allocator makes HeapTerminatedArray instances for
52 // HeapTerminatedArrayBuilder by pointer casting. 55 // HeapTerminatedArrayBuilder by pointer casting.
53 HeapTerminatedArray(); 56 HeapTerminatedArray();
54 57
55 template <typename U, template <typename> class> 58 template <typename U, template <typename> class>
56 friend class WTF::TerminatedArrayBuilder; 59 friend class WTF::TerminatedArrayBuilder;
57 }; 60 };
58 61
59 template <typename T> 62 template <typename T>
60 class TraceEagerlyTrait<HeapTerminatedArray<T>> { 63 class TraceEagerlyTrait<HeapTerminatedArray<T>> {
61 public: 64 public:
62 static const bool value = TraceEagerlyTrait<T>::value; 65 static const bool value = TraceEagerlyTrait<T>::value;
63 }; 66 };
64 67
65 } // namespace blink 68 } // namespace blink
66 69
67 #endif // HeapTerminatedArray_h 70 #endif // HeapTerminatedArray_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSSelectorList.cpp ('k') | third_party/WebKit/Source/platform/wtf/TerminatedArray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698