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); |