diff options
author | Diego 'Flameeyes' Pettenò <flameeyes@gmail.com> | 2007-04-14 17:12:05 +0200 |
---|---|---|
committer | Diego 'Flameeyes' Pettenò <flameeyes@gmail.com> | 2007-04-14 17:12:05 +0200 |
commit | b10d5cccee5d2945b1924a732a9b7d9d79d91b0b (patch) | |
tree | 51f0349cbb1081af758eee5455f094d0b7c171d5 /src/xine-utils/utils.c | |
parent | 9c7b147a1878bd2c9290bb3377f41bc4a27ddccd (diff) | |
download | xine-lib-b10d5cccee5d2945b1924a732a9b7d9d79d91b0b.tar.gz xine-lib-b10d5cccee5d2945b1924a732a9b7d9d79d91b0b.tar.bz2 |
Add a xine_xcalloc function to wrap around calloc(), to improve security from now on.
Diffstat (limited to 'src/xine-utils/utils.c')
-rw-r--r-- | src/xine-utils/utils.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index fa0c11dbe..63c2e2f09 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -256,6 +256,27 @@ void *xine_xmalloc(size_t size) { return ptr; } +/** + * @brief Wrapper around calloc() function. + * @param nmemb Number of elements to allocate + * @param size Size of each element to allocate + * + * This is a simple wrapper around calloc(), the only thing + * it does more than calloc() is outputting an error if + * the calloc fails (returning NULL). + */ +void *xine_xcalloc(size_t nmemb, size_t size) { + void *ptr; + + if((ptr = calloc(nmemb, size)) == NULL) { + fprintf(stderr, "%s: calloc() failed: %s.\n", + __XINE_FUNCTION__, strerror(errno)); + return NULL; + } + + return ptr; +} + void *xine_xmalloc_aligned(size_t alignment, size_t size, void **base) { char *ptr; |