Convert MALLOC to actually call malloc()

If you need zero-filled allocations, call CALLOC() instead.

This was from the original definition of these macros in commit
cc754bc6e3be0f3; hopefully our code is in the shape it needs to be to
switch this behavior.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-09-30 11:46:44 -05:00
parent 980b3faea5
commit 89fe19f3e1
2 changed files with 3 additions and 3 deletions

View File

@ -682,11 +682,11 @@ static int apply_deltas(alpm_handle_t *handle)
} else {
/* len = cachedir len + from len + '/' + null */
len = strlen(cachedir) + strlen(d->from) + 2;
CALLOC(from, len, sizeof(char), RET_ERR(handle, ALPM_ERR_MEMORY, 1));
MALLOC(from, len, RET_ERR(handle, ALPM_ERR_MEMORY, 1));
snprintf(from, len, "%s/%s", cachedir, d->from);
}
len = strlen(cachedir) + strlen(d->to) + 2;
CALLOC(to, len, sizeof(char), RET_ERR(handle, ALPM_ERR_MEMORY, 1));
MALLOC(to, len, RET_ERR(handle, ALPM_ERR_MEMORY, 1));
snprintf(to, len, "%s/%s", cachedir, d->to);
/* build the patch command */

View File

@ -50,7 +50,7 @@
#define ALLOC_FAIL(s) do { fprintf(stderr, "alloc failure: could not allocate %zd bytes\n", s); } while(0)
#define MALLOC(p, s, action) do { p = calloc(1, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
#define MALLOC(p, s, action) do { p = malloc(s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
#define CALLOC(p, l, s, action) do { p = calloc(l, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
/* This strdup macro is NULL safe- copying NULL will yield NULL */
#define STRDUP(r, s, action) do { if(s != NULL) { r = strdup(s); if(r == NULL) { ALLOC_FAIL(strlen(s)); action; } } else { r = NULL; } } while(0)