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

Side by Side Diff: runtime/platform/utils.h

Issue 16271010: Use 'new' in all the snapshot reallocation functions instead of realloc. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef PLATFORM_UTILS_H_ 5 #ifndef PLATFORM_UTILS_H_
6 #define PLATFORM_UTILS_H_ 6 #define PLATFORM_UTILS_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "platform/globals.h" 9 #include "platform/globals.h"
10 10
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // without the risk of integer overflow. 164 // without the risk of integer overflow.
165 static inline bool RangeCheck(intptr_t offset, 165 static inline bool RangeCheck(intptr_t offset,
166 intptr_t count, 166 intptr_t count,
167 intptr_t length) { 167 intptr_t length) {
168 return offset >= 0 && 168 return offset >= 0 &&
169 count >= 0 && 169 count >= 0 &&
170 length >= 0 && 170 length >= 0 &&
171 count <= (length - offset); 171 count <= (length - offset);
172 } 172 }
173 173
174 template <class ElementType>
175 static inline ElementType* Realloc(ElementType* old_data,
176 intptr_t old_len,
177 intptr_t new_len) {
178 if ((old_len * sizeof(ElementType)) >=
srdjan 2013/06/04 20:15:58 greater only
siva 2013/06/05 16:21:31 Done.
179 (new_len * sizeof(ElementType))) {
180 FATAL2("Realloc overflow: "
181 "'old_size'=%"Pd",'new_size'=%"Pd,
182 (old_len * sizeof(ElementType)),
183 (new_len * sizeof(ElementType)));
184 }
185 ElementType* new_data = new ElementType[new_len];
186 if (old_data != 0) {
srdjan 2013/06/04 20:15:58 != NULL
siva 2013/06/05 16:21:31 Done.
187 memmove(reinterpret_cast<void*>(new_data),
188 reinterpret_cast<void*>(old_data),
189 Utils::Minimum(old_len * sizeof(ElementType),
srdjan 2013/06/04 20:15:58 Just old_len
siva 2013/06/05 16:21:31 Done.
190 new_len * sizeof(ElementType)));
191 delete[] old_data;
192 }
193 return new_data;
194 }
195
174 // Utility functions for converting values from host endianess to 196 // Utility functions for converting values from host endianess to
175 // big or little endian values. 197 // big or little endian values.
176 static uint16_t HostToBigEndian16(uint16_t host_value); 198 static uint16_t HostToBigEndian16(uint16_t host_value);
177 static uint32_t HostToBigEndian32(uint32_t host_value); 199 static uint32_t HostToBigEndian32(uint32_t host_value);
178 static uint64_t HostToBigEndian64(uint64_t host_value); 200 static uint64_t HostToBigEndian64(uint64_t host_value);
179 static uint16_t HostToLittleEndian16(uint16_t host_value); 201 static uint16_t HostToLittleEndian16(uint16_t host_value);
180 static uint32_t HostToLittleEndian32(uint32_t host_value); 202 static uint32_t HostToLittleEndian32(uint32_t host_value);
181 static uint64_t HostToLittleEndian64(uint64_t host_value); 203 static uint64_t HostToLittleEndian64(uint64_t host_value);
182 }; 204 };
183 205
184 } // namespace dart 206 } // namespace dart
185 207
186 #if defined(TARGET_OS_ANDROID) 208 #if defined(TARGET_OS_ANDROID)
187 #include "platform/utils_android.h" 209 #include "platform/utils_android.h"
188 #elif defined(TARGET_OS_LINUX) 210 #elif defined(TARGET_OS_LINUX)
189 #include "platform/utils_linux.h" 211 #include "platform/utils_linux.h"
190 #elif defined(TARGET_OS_MACOS) 212 #elif defined(TARGET_OS_MACOS)
191 #include "platform/utils_macos.h" 213 #include "platform/utils_macos.h"
192 #elif defined(TARGET_OS_WINDOWS) 214 #elif defined(TARGET_OS_WINDOWS)
193 #include "platform/utils_win.h" 215 #include "platform/utils_win.h"
194 #else 216 #else
195 #error Unknown target os. 217 #error Unknown target os.
196 #endif 218 #endif
197 219
198 #endif // PLATFORM_UTILS_H_ 220 #endif // PLATFORM_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698