diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2014-02-19 16:02:52 -0500 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2014-02-19 16:02:52 -0500 |
commit | ac86133781d7cd50964579f79522a4e3f8c3f339 (patch) | |
tree | 2bd3d58125e48b9c4439b7f22eb22f0d7a5ffab1 /FEAST/MIToolbox/util.c | |
parent | 7889905d7478f31d8092187cd104beee39972ebb (diff) |
add a safe alloc function so our program doesn't segfault on memory shortage
Diffstat (limited to 'FEAST/MIToolbox/util.c')
-rw-r--r-- | FEAST/MIToolbox/util.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/FEAST/MIToolbox/util.c b/FEAST/MIToolbox/util.c new file mode 100644 index 0000000..d9d7517 --- /dev/null +++ b/FEAST/MIToolbox/util.c @@ -0,0 +1,14 @@ +#include <string.h> +#include <errno.h> + +#include "MIToolbox.h" + +// a wrapper for calloc that checks if it's allocated +void *safe_calloc(size_t nelem, size_t elsize) { + void *allocated = UNSAFE_CALLOC_FUNC(nelem, elsize); + if(allocated == NULL) { + fprintf(stderr, "Error: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + return allocated; +} |