Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/alpm_list.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-11-14 22:51:16 -0600
committerDan McGee <dan@archlinux.org>2007-11-14 22:51:16 -0600
commitf75ee7176235f2c1a531113985d715ddcafb6d05 (patch)
tree0b43fc0659f6049dddd65624239fb3a0b30cab4c /lib/libalpm/alpm_list.c
parentc244cfecf654d34032585530f00d68501ec63d77 (diff)
Fix alpm_list_copy_data
So I spent a good 4 hours tracking a bug down tonight due to alpm_list_copy_data not actually doing what I expected to do. We can't find the size of an object we don't know the type of, so rewrite it so we pass in the size explicitly. This was making _alpm_pkg_dup fail and causing all sorts of other issues. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/alpm_list.c')
-rw-r--r--lib/libalpm/alpm_list.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index 774d1dbe..c1e4cb8e 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -399,21 +399,23 @@ alpm_list_t SYMEXPORT *alpm_list_copy(const alpm_list_t *list)
/**
* @brief Copy a list and copy the data.
- *
- * The data must be constant size!
+ * Note that the data elements to be copied should not contain pointers
+ * and should also be of constant size.
*
* @param list the list to copy
+ * @param size the size of each data element
*
* @return a copy of the original list, data copied as well
*/
-alpm_list_t SYMEXPORT *alpm_list_copy_data(const alpm_list_t *list)
+alpm_list_t SYMEXPORT *alpm_list_copy_data(const alpm_list_t *list,
+ size_t size)
{
const alpm_list_t *lp = list;
alpm_list_t *newlist = NULL;
while(lp) {
- void *newdata = calloc(1, sizeof(lp->data));
+ void *newdata = calloc(1, size);
if(newdata) {
- memcpy(newdata, lp->data, sizeof(lp->data));
+ memcpy(newdata, lp->data, size);
newlist = alpm_list_add(newlist, newdata);
lp = lp->next;
}