Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libalpm/add.c13
-rw-r--r--lib/libalpm/db.c11
-rw-r--r--lib/libalpm/package.c10
-rw-r--r--lib/libalpm/util.h11
4 files changed, 27 insertions, 18 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 5d29abdd..e3c5174c 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -57,7 +57,8 @@ static int add_faketarget(pmtrans_t *trans, char *name)
char *str = NULL;
pmpkg_t *dummy = NULL;
- if((dummy = _alpm_pkg_new(NULL, NULL)) == NULL) {
+ dummy = _alpm_pkg_new(NULL, NULL);
+ if(dummy == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
@@ -457,7 +458,10 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
if(!strcmp(file, pathname)) {
char *fn;
/* 32 for the hash, 1 for the terminating NULL, and 1 for the tab delimiter */
- MALLOC(fn, strlen(file)+34);
+ fn = (char *)malloc(strlen(file)+34);
+ if(fn == NULL) {
+ RET_ERR(PM_ERR_MEMORY, -1);
+ }
sprintf(fn, "%s\t%s", file, md5_pkg);
FREE(file);
lp->data = fn;
@@ -568,7 +572,10 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
snprintf(path, PATH_MAX, "%s%s", handle->root, file);
md5 = MDFile(path);
/* 32 for the hash, 1 for the terminating NULL, and 1 for the tab delimiter */
- MALLOC(fn, strlen(file)+34);
+ fn = (char *)malloc(strlen(file)+34);
+ if(fn == NULL) {
+ RET_ERR(PM_ERR_MEMORY, -1);
+ }
sprintf(fn, "%s\t%s", file, md5);
FREE(md5);
FREE(file);
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index e4987dd6..a81d5406 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -32,6 +32,7 @@
/* pacman */
#include "log.h"
#include "util.h"
+#include "error.h"
#include "group.h"
#include "cache.h"
#include "db.h"
@@ -48,9 +49,15 @@ pmdb_t *_alpm_db_open(char *dbpath, char *treename, int mode)
_alpm_log(PM_LOG_DEBUG, "opening database '%s'", treename);
- MALLOC(db, sizeof(pmdb_t));
+ db = (pmdb_t *)malloc(sizeof(pmdb_t));
+ if(db == NULL) {
+ RET_ERR(PM_ERR_MEMORY, NULL);
+ }
- MALLOC(db->path, strlen(dbpath)+strlen(treename)+2);
+ db->path = (char *)malloc(strlen(dbpath)+strlen(treename)+2);
+ if(db->path == NULL) {
+ RET_ERR(PM_ERR_MEMORY, NULL);
+ }
sprintf(db->path, "%s/%s", dbpath, treename);
db->dir = opendir(db->path);
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 7767297a..fe568fe0 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -39,7 +39,10 @@ pmpkg_t *_alpm_pkg_new(const char *name, const char *version)
{
pmpkg_t* pkg = NULL;
- MALLOC(pkg, sizeof(pmpkg_t));
+ pkg = (pmpkg_t *)malloc(sizeof(pmpkg_t));
+ if(pkg == NULL) {
+ RET_ERR(PM_ERR_MEMORY, NULL);
+ }
if(name && name[0] != 0) {
STRNCPY(pkg->name, name, PKG_NAME_LEN);
@@ -313,7 +316,10 @@ pmpkg_t *_alpm_pkg_load(char *pkgfile)
char *str;
int fd;
- MALLOC(str, PATH_MAX);
+ str = (char *)malloc(PATH_MAX);
+ if(str == NULL) {
+ RET_ERR(PM_ERR_MEMORY, NULL);
+ }
fn = strdup("/tmp/alpm_XXXXXX");
fd = mkstemp(fn);
tar_extract_file(tar, fn);
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 225820e1..7b24961c 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -23,17 +23,6 @@
#include <stdio.h>
-#define MALLOC(p, b) { \
- if((b) > 0) { \
- p = malloc(b); \
- if (!(p)) { \
- fprintf(stderr, "malloc failure: could not allocate %d bytes\n", (b)); \
- exit(1); \
- } \
- } else { \
- p = NULL; \
- } \
-}
#define FREE(p) do { if (p) { free(p); p = NULL; } } while(0)
#define ASSERT(cond, action) do { if(!(cond)) { action; } } while(0)