[pacman-dev] [BUG] alpm_list_remove need an initalized pointer for void **data

Dan McGee dpmcgee at gmail.com
Fri Aug 8 07:47:55 EDT 2008


On Fri, Aug 8, 2008 at 6:32 AM, Xavier <shiningxc at gmail.com> wrote:
> On Thu, Aug 7, 2008 at 3:41 PM, Dan McGee <dpmcgee at gmail.com> wrote:
>>
>> I think the problem is something different; note the problem occurs in db_cmp:
>>
>> Program received signal SIGSEGV, Segmentation fault.
>> _alpm_db_cmp (d1=0x97b60f0, d2=0x97b60f0) at db.c:363
>> 363             return(strcmp(db1->treename, db2->treename));
>> (gdb) bt
>> #0  _alpm_db_cmp (d1=0x97b60f0, d2=0x97b60f0) at db.c:363
>> #1  0xb8006a8c in alpm_list_remove (haystack=0x97b6140, needle=0x97b60f0,
>>    fn=0xb800d5b0 <_alpm_db_cmp>, data=0xbf841064) at alpm_list.c:314
>> #2  0xb800ead2 in alpm_db_unregister (db=0x97b60f0) at db.c:149
>> #3  0x08048770 in main () at test.c:17
>> (gdb) p d1
>> $1 = (const void *) 0x97b60f0
>> (gdb) p d2
>> $2 = (const void *) 0x97b60f0
>> (gdb) p d1->treename
>> Attempt to dereference a generic pointer.
>> (gdb) p ((pmdb_t)d1)->treename
>> $3 = 0x97b60f0 "\020a{\t0a{\t\220p{\t"
>> (gdb) p ((pmdb_t)d2)->treename
>> $4 = 0x0
>>
>
> -int _alpm_db_cmp(const void *db1, const void *db2)
> +int _alpm_db_cmp(const void *d1, const void *d2)
>  {
> -       ALPM_LOG_FUNC;
> -       return(strcmp(((pmdb_t *)db1)->treename, ((pmdb_t *)db2)->treename));
> +       pmdb_t *db1 = (pmdb_t *)db1;
> +       pmdb_t *db2 = (pmdb_t *)db2;
> +       return(strcmp(db1->treename, db2->treename));
>  }
>
> Oh my god, who could have wrote such a stupid code :@
>
> commit f43805d875ad5c672afbbfff48bded2087204773
> Author: Chantry Xavier <shiningxc at gmail.com>
> Date:   Sat May 10 18:47:42 2008 +0200
>
> Oh my god, it was me.
> /me bangs his head against the wall 100 times.

Why on earth did that even compile? This seems to work just fine:

diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index d9a3931..191c8ba 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -358,8 +358,8 @@ void _alpm_db_free(pmdb_t *db)

 int _alpm_db_cmp(const void *d1, const void *d2)
 {
-       pmdb_t *db1 = (pmdb_t *)db1;
-       pmdb_t *db2 = (pmdb_t *)db2;
+       pmdb_t *db1 = (pmdb_t *)d1;
+       pmdb_t *db2 = (pmdb_t *)d2;
        return(strcmp(db1->treename, db2->treename));
 }

diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index eb0af1a..96fac0d 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -50,7 +50,7 @@ struct __pmdb_t {
 /* db.c, database general calls */
 pmdb_t *_alpm_db_new(const char *dbpath, const char *treename);
 void _alpm_db_free(pmdb_t *db);
-int _alpm_db_cmp(const void *db1, const void *db2);
+int _alpm_db_cmp(const void *d1, const void *d2);
 alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles);
 pmdb_t *_alpm_db_register_local(void);
 pmdb_t *_alpm_db_register_sync(const char *treename);



More information about the pacman-dev mailing list