Package: tinycdb
Version: 0.74-1
Tags: patch

If dlenp arg of cdb_seek point to the integer variable whose value is 0,
cdb_seek does not set dlenp correctly.  This behavior is not documented
and I think it is unintended.  Due to this, the dbskkd-cdb package
compiled with gcc-4.0 does not work well.

To reproduce

$ echo "+3,5:one->Hello\n" | cdbmake test.cdb test.cdb.tmp
$ gcc -o testcdb testcdb.c -lcdb
$ ./testcdb ./test.cdb one
dlen = 0 # <- it should be 5
$ cat testcdb.c
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <cdb.h>

int main (int argc, char **argv)
{
  int fd, ret;
  const char *key;
  unsigned klen, dlen = 0; // if dlen = 1, it works as expected

  assert (argc == 3);
  fd = open (argv[1], O_RDONLY);
  if (fd == -1)
    {
      perror ("open");
      return 1;
    }

  key = argv[2];
  klen = strlen (key);
  ret = cdb_seek (fd, key, klen, &dlen);
  if (ret == -1)
    return 1;
  else if (ret == 0)
    printf ("not found");
  else
    printf ("dlen = %d\n", dlen);

  return 0;
}

Here is a patch to fix it

--- cdb_seek.c~ 2006-08-17 15:02:16.000000000 +0900
+++ cdb_seek.c  2006-08-17 15:02:43.000000000 +0900
@@ -75,7 +75,7 @@
        /* read the key from file and compare with wanted */
        unsigned l = klen, c;
        const char *k = (const char*)key;
-       if (*dlenp)
+       if (dlenp)
          *dlenp = cdb_unpack(rbuf + 4); /* save value length */
        for(;;) {
          if (!l) /* the whole key read and matches, return */

Regards,
-- 
Daiki Ueno


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to