aboutsummaryrefslogtreecommitdiff
path: root/memory.h
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-03-14 11:05:35 +0100
committertomsmeding <tom.smeding@gmail.com>2017-03-14 11:05:35 +0100
commit54064158d84fc4006e651deb314cde156cc383e8 (patch)
treea534f160fe02b593143e03aaaf52f65513352c90 /memory.h
Register working
Diffstat (limited to 'memory.h')
-rw-r--r--memory.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/memory.h b/memory.h
new file mode 100644
index 0000000..970648f
--- /dev/null
+++ b/memory.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <stdlib.h>
+
+#define malloc(num,type) \
+ ((type*)check_after_allocation("malloc",num,sizeof(type),malloc((num)*sizeof(type))))
+#define calloc(num,type) \
+ ((type*)check_after_allocation("calloc",num,sizeof(type),calloc((num),sizeof(type))))
+#define realloc(ptr,num,type) \
+ ((type*)check_after_allocation("realloc",num,sizeof(type),realloc((ptr),(num)*sizeof(type))))
+
+void* check_after_allocation(const char *func,size_t num,size_t sz,void *ptr);