Make explicit the difference between a tdb key with no data attached, and
authorJeremy Allison <jra@samba.org>
Thu, 26 Sep 2002 21:02:47 +0000 (21:02 +0000)
committerJeremy Allison <jra@samba.org>
Thu, 26 Sep 2002 21:02:47 +0000 (21:02 +0000)
a non existent entry. Stop a malloc(0) being called in the first case.
Jeremy.
(This used to be commit 7b841247bda028ce654fb760b932f08ec61c494c)

source3/tdb/tdb.c

index 5bb75ffe07792cd6eb547f0fa78805859588de64..4143ac7781900cdbd5f1ad2c7fc82d5ba346f1a3 100644 (file)
@@ -1048,6 +1048,12 @@ static int tdb_update(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf)
 }
 
 /* find an entry in the database given a key */
+/* If an entry doesn't exist tdb_err will be set to
+ * TDB_ERR_NOEXIST. If a key has no data attached
+ * tdb_err will not be set. Both will return a
+ * zero pptr and zero dsize.
+ */
+
 TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key)
 {
        tdb_off rec_ptr;
@@ -1058,8 +1064,11 @@ TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key)
        if (!(rec_ptr = tdb_find_lock(tdb,key,F_RDLCK,&rec)))
                return tdb_null;
 
-       ret.dptr = tdb_alloc_read(tdb, rec_ptr + sizeof(rec) + rec.key_len,
-                                 rec.data_len);
+       if (rec.data_len)
+               ret.dptr = tdb_alloc_read(tdb, rec_ptr + sizeof(rec) + rec.key_len,
+                                         rec.data_len);
+       else
+               ret.dptr = NULL;
        ret.dsize = rec.data_len;
        tdb_unlock(tdb, BUCKET(rec.full_hash), F_RDLCK);
        return ret;