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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: runtime/platform/utils.h
===================================================================
--- runtime/platform/utils.h (revision 23570)
+++ runtime/platform/utils.h (working copy)
@@ -171,6 +171,28 @@
count <= (length - offset);
}
+ template <class ElementType>
+ static inline ElementType* Realloc(ElementType* old_data,
+ intptr_t old_len,
+ intptr_t new_len) {
+ if ((old_len * sizeof(ElementType)) >=
srdjan 2013/06/04 20:15:58 greater only
siva 2013/06/05 16:21:31 Done.
+ (new_len * sizeof(ElementType))) {
+ FATAL2("Realloc overflow: "
+ "'old_size'=%"Pd",'new_size'=%"Pd,
+ (old_len * sizeof(ElementType)),
+ (new_len * sizeof(ElementType)));
+ }
+ ElementType* new_data = new ElementType[new_len];
+ if (old_data != 0) {
srdjan 2013/06/04 20:15:58 != NULL
siva 2013/06/05 16:21:31 Done.
+ memmove(reinterpret_cast<void*>(new_data),
+ reinterpret_cast<void*>(old_data),
+ Utils::Minimum(old_len * sizeof(ElementType),
srdjan 2013/06/04 20:15:58 Just old_len
siva 2013/06/05 16:21:31 Done.
+ new_len * sizeof(ElementType)));
+ delete[] old_data;
+ }
+ return new_data;
+ }
+
// Utility functions for converting values from host endianess to
// big or little endian values.
static uint16_t HostToBigEndian16(uint16_t host_value);

Powered by Google App Engine
This is Rietveld 408576698