From d692f9373cdd43c2c3077b3250726cb508cff00d Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Tue, 10 Jan 2017 00:53:32 +1000 Subject: [PATCH] * drop CALLOC() macro --- src/bitmap.c | 6 +++++- src/common.h | 7 ------- src/database.c | 9 ++++++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/bitmap.c b/src/bitmap.c index b9252b7..2131ebb 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -81,7 +81,11 @@ simdb_bitmap_unpack(const unsigned char *map, uint16_t *p, row, mask; unsigned char *q = NULL; - CALLOC(*buf, buf_size, sizeof(char)); + assert(map != NULL); + assert(buf != NULL); + + if ((*buf = calloc(buf_size, sizeof(char))) == NULL) + return 0; p = (uint16_t *) map; q = *buf; diff --git a/src/common.h b/src/common.h index 0114888..512e36f 100644 --- a/src/common.h +++ b/src/common.h @@ -19,13 +19,6 @@ #include #include -/** @defgroup MemoryMgmt Memory management macro - * @{*/ /** frees memory and sets pointer to zero */ #define FREE(ptr) \ free((ptr)); (ptr) = NULL; - -/** allocates memory, and checks is it really allocated */ -#define CALLOC(ptr, nmemb, size) \ - assert(((ptr) = calloc((nmemb), (size))) != NULL); -/** @} */ diff --git a/src/database.c b/src/database.c index a874095..dbc0c6c 100644 --- a/src/database.c +++ b/src/database.c @@ -356,7 +356,8 @@ simdb_search(simdb_t * const db, int num, if (search->maxdiff_ratio > 0.0) ratio_s = simdb_record_ratio(&sample); - CALLOC(*matches, search->limit, sizeof(simdb_match_t)); + if ((*matches = calloc(search->limit, sizeof(simdb_match_t))) == NULL) + return SIMDB_ERR_OOM; for (num = 1; ; num += blksize) { ret = simdb_read(db, num, blksize, &data); @@ -413,7 +414,8 @@ simdb_usage_map(simdb_t * const db, char ** const map) { assert(map != NULL); records = simdb_records_count(db); - CALLOC(m, records + 1, sizeof(char)); + if ((m = calloc(records + 1, sizeof(char))) == NULL) + return SIMDB_ERR_OOM; *map = m; for (int num = 1; ; num += blksize) { @@ -451,7 +453,8 @@ simdb_usage_slice(simdb_t * const db, char ** const map, int offset, int limit) if (ret <= 0) return ret; - CALLOC(m, limit + 1, sizeof(char)); + if ((m = calloc(limit + 1, sizeof(char))) == NULL) + return SIMDB_ERR_OOM; m = *map; r = data;