summaryrefslogtreecommitdiff
path: root/src/helpers.hpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-12-08 14:50:41 +0000
committerrubidium <rubidium@openttd.org>2007-12-08 14:50:41 +0000
commitf1e4914b5f379f9821274e8ddc4196b152fcc9b0 (patch)
treeb8ebe2d1af4279edf6f4a53f991c963c77f5bba0 /src/helpers.hpp
parent73c58d8a409d7e5f3dbb864be893a1c0b34defd6 (diff)
downloadopenttd-f1e4914b5f379f9821274e8ddc4196b152fcc9b0.tar.xz
(svn r11597) -Change: replace all remaining instances of (re|m|c)alloc with (Re|M|C)allocT and add a check for out-of-memory situations to the *allocT functions.
Diffstat (limited to 'src/helpers.hpp')
-rw-r--r--src/helpers.hpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/helpers.hpp b/src/helpers.hpp
index 3edbcf3b8..651cb0f3c 100644
--- a/src/helpers.hpp
+++ b/src/helpers.hpp
@@ -12,6 +12,7 @@
template <typename T> FORCEINLINE T* MallocT(size_t num_elements)
{
T *t_ptr = (T*)malloc(num_elements * sizeof(T));
+ if (t_ptr == NULL && num_elements != 0) error("Out of memory. Cannot allocate %i bytes", num_elements * sizeof(T));
return t_ptr;
}
/** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
@@ -19,6 +20,7 @@ template <typename T> FORCEINLINE T* MallocT(size_t num_elements)
template <typename T> FORCEINLINE T* CallocT(size_t num_elements)
{
T *t_ptr = (T*)calloc(num_elements, sizeof(T));
+ if (t_ptr == NULL && num_elements != 0) error("Out of memory. Cannot allocate %i bytes", num_elements * sizeof(T));
return t_ptr;
}
/** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
@@ -26,6 +28,7 @@ template <typename T> FORCEINLINE T* CallocT(size_t num_elements)
template <typename T> FORCEINLINE T* ReallocT(T* t_ptr, size_t num_elements)
{
t_ptr = (T*)realloc(t_ptr, num_elements * sizeof(T));
+ if (t_ptr == NULL && num_elements != 0) error("Out of memory. Cannot reallocate %i bytes", num_elements * sizeof(T));
return t_ptr;
}