+Tue Jul 23 16:08:43 1996 Ezra Peisach <epeisach@kangaroo.mit.edu>
+
+ * hash/dbm.c: Copy elements from the datum to an internal
+ DBT. Handles case of differences in size of size fields.
+
Fri Jun 21 00:07:57 1996 Marc Horowitz <marc@mit.edu>
* hash/dbm.c (delete, store): dbm_rdonly() doesn't exist on some
#include "db-ndbm.h"
#include "hash.h"
+/* If the two size fields of datum and DBMT are not equal, then
+ * casting between structures will result in stack garbage being
+ * transfered. Has been observed for DEC Alpha OSF, but will handle
+ * the general case.
+ */
+
+#define NEED_COPY
+
/*
*
* This package provides dbm and ndbm compatible interfaces to DB.
datum retval;
int status;
+#ifdef NEED_COPY
+ DBT k, r;
+
+ k.data = key.dptr;
+ k.size = key.dsize;
+ status = (db->get)(db, &k, &r, 0);
+ retval.dptr = r.data;
+ retval.dsize = r.size;
+#else
status = (db->get)(db, (DBT *)&key, (DBT *)&retval, 0);
+#endif
if (status) {
retval.dptr = NULL;
retval.dsize = 0;
int status;
datum retdata, retkey;
+#ifdef NEED_COPY
+ DBT k, r;
+
+ status = (db->seq)(db, &k, &r, R_FIRST);
+ retkey.dptr = k.data;
+ retkey.dsize = k.size;
+#else
status = (db->seq)(db, (DBT *)&retkey, (DBT *)&retdata, R_FIRST);
+#endif
if (status)
retkey.dptr = NULL;
return (retkey);
int status;
datum retdata, retkey;
+#ifdef NEED_COPY
+ DBT k, r;
+
+ status = (db->seq)(db, &k, &r, R_NEXT);
+ retkey.dptr = k.data;
+ retkey.dsize = k.size;
+#else
status = (db->seq)(db, (DBT *)&retkey, (DBT *)&retdata, R_NEXT);
+#endif
if (status)
retkey.dptr = NULL;
return (retkey);
{
int status;
+#ifdef NEED_COPY
+ DBT k;
+
+ k.data = key.dptr;
+ k.size = key.dsize;
+ status = (db->del)(db, &k, 0);
+#else
status = (db->del)(db, (DBT *)&key, 0);
+#endif
if (status)
return (-1);
else
datum key, content;
int flags;
{
+#ifdef NEED_COPY
+ DBT k, c;
+
+ k.data = key.dptr;
+ k.size = key.dsize;
+ c.data = content.dptr;
+ c.size = content.dsize;
+ return ((db->put)(db, &k, &c,
+ (flags == DBM_INSERT) ? R_NOOVERWRITE : 0));
+#else
return ((db->put)(db, (DBT *)&key, (DBT *)&content,
(flags == DBM_INSERT) ? R_NOOVERWRITE : 0));
+#endif
}
int