> -----Original Message-----
> From: Greg Stein [mailto:[EMAIL PROTECTED]
> Sent: 17. rujan 2001 13:57
> To: Mladen Turk
> Cc: APR Dev List
> Subject: Re: [PATCH] apr_dbm -- db fix
>
> -1 -- this patch should not be applied.
>
> The change to RETURN_DATUM is wrong. The result of the NEXTKEY is
placed
> into "rd", and that is returned. If DB's do_nextkey is putting the
result
> into *pkey rather than *pnext, then *that* is the bug. But changing
the
> RETURN_DATUM call is wrong.
>
> I *know* that the apr_dbm_nextkey() function is working. If DB isn't,
then
> you should question the macros instead.
>
[Mladen Turk]
Sorry but did you try to run the testdbm utility?
I've tested it using db-1.85 and db-3.3.11
1. Insert some values using 'testdbm build whatever'
2. Run 'testdbm list whatever'
3. After the first record read you'll get a segfault
The Berkeley DB docs are even stating that DBcursor->c_get returns
key/data pair, so why would you copy data to key?
Now, when I apply the patch, on db-3.3.11 I have a infinite loop. The
reason for that is that data DBT must be memset to zero.
Here is the complete patch. I've tested it on WIN32 using db-1.85 and
db-3.3.11.
If someone has some doubts I suggest him to run the testdbm and see for
himself.
MT.
Index: apr_dbm.c
===================================================================
RCS file: /home/cvspublic/apr-util/dbm/apr_dbm.c,v
retrieving revision 1.27
diff -u -r1.27 apr_dbm.c
--- apr_dbm.c 2001/08/29 18:34:05 1.27
+++ apr_dbm.c 2001/09/18 07:54:20
@@ -255,8 +255,13 @@
int dberr;
DBT data;
+ memset(&data,0,sizeof(DBT));
#if DB_VER == 1
dberr = (*f->bdb->seq)(f->bdb, pkey, &data, R_NEXT);
+ if (dberr == RET_SPECIAL) {
+ pkey->data = NULL;
+ pkey->size = 0;
+ }
#else
if (f->curs == NULL)
return APR_EINVAL;
@@ -553,7 +558,7 @@
CONVERT_DATUM(ckey, pkey);
rv = APR_DBM_NEXTKEY(dbm->file, ckey, rd);
- RETURN_DATUM(pkey, rd);
+ RETURN_DATUM(pkey, ckey);
REGISTER_CLEANUP(dbm, pkey);