Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/be_local.c4
-rw-r--r--lib/libalpm/be_package.c2
-rw-r--r--lib/libalpm/util.c5
-rw-r--r--lib/libalpm/util.h10
4 files changed, 13 insertions, 8 deletions
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 227bc9bc..30e59d00 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -667,7 +667,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
}
files = realloc(files, sizeof(alpm_file_t) * files_size);
if(!files) {
- ALLOC_FAIL(sizeof(alpm_file_t) * files_size);
+ _alpm_alloc_fail(sizeof(alpm_file_t) * files_size);
goto error;
}
/* ensure all new memory is zeroed out, in both the initial
@@ -680,7 +680,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
len += 1;
files[files_count].name = malloc(len);
if(files[files_count].name == NULL) {
- ALLOC_FAIL(len);
+ _alpm_alloc_fail(len);
goto error;
}
memcpy(files[files_count].name, line, len);
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index bcb884f4..0d296a81 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -476,7 +476,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
newfiles = realloc(newpkg->files.files,
sizeof(alpm_file_t) * files_size);
if(!newfiles) {
- ALLOC_FAIL(sizeof(alpm_file_t) * files_size);
+ _alpm_alloc_fail(sizeof(alpm_file_t) * files_size);
goto error;
}
/* ensure all new memory is zeroed out, in both the initial
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index a392c773..996d7f4e 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -1247,6 +1247,11 @@ int _alpm_fnmatch(const void *pattern, const void *string)
return fnmatch(pattern, string, 0);
}
+void _alpm_alloc_fail(size_t size)
+{
+ fprintf(stderr, "alloc failure: could not allocate %zd bytes\n", size);
+}
+
#ifndef HAVE_STRNDUP
/* A quick and dirty implementation derived from glibc */
/** Determines the length of a fixed-size string.
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index e35e35b9..87d51eaa 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -49,13 +49,13 @@
#define _(s) s
#endif
-#define ALLOC_FAIL(s) do { fprintf(stderr, "alloc failure: could not allocate %zd bytes\n", s); } while(0)
+void _alpm_alloc_fail(size_t size);
-#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(l * s); action; } } while(0)
+#define MALLOC(p, s, action) do { p = malloc(s); if(p == NULL) { _alpm_alloc_fail(s); action; } } while(0)
+#define CALLOC(p, l, s, action) do { p = calloc(l, s); if(p == NULL) { _alpm_alloc_fail(l * 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)
-#define STRNDUP(r, s, l, action) do { if(s != NULL) { r = strndup(s, l); if(r == NULL) { ALLOC_FAIL(strlen(s)); action; } } else { r = NULL; } } while(0)
+#define STRDUP(r, s, action) do { if(s != NULL) { r = strdup(s); if(r == NULL) { _alpm_alloc_fail(strlen(s)); action; } } else { r = NULL; } } while(0)
+#define STRNDUP(r, s, l, action) do { if(s != NULL) { r = strndup(s, l); if(r == NULL) { _alpm_alloc_fail(l); action; } } else { r = NULL; } } while(0)
#define FREE(p) do { free(p); p = NULL; } while(0)