Page MenuHomeFreeBSD

D57670.diff
No OneTemporary

D57670.diff

diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c
--- a/lib/libc/db/hash/hash.c
+++ b/lib/libc/db/hash/hash.c
@@ -81,6 +81,10 @@
#define ERROR (-1)
#define ABNORMAL (1)
+/* Cursor status */
+#define CURSOR_NOT_SET -1
+#define CURSOR_OVERFLOW -2
+
#ifdef HASH_STATISTICS
int hash_accesses, hash_collisions, hash_expansions, hash_overflows;
#endif
@@ -180,7 +184,7 @@
hashp->new_file = new_table;
hashp->save_file = file && (flags & O_RDWR);
- hashp->cbucket = -1;
+ hashp->cbucket = CURSOR_NOT_SET;
if (!(dbp = (DB *)malloc(sizeof(DB)))) {
save_errno = errno;
hdestroy(hashp);
@@ -711,11 +715,11 @@
#ifdef HASH_STATISTICS
hash_accesses++;
#endif
- if (flag == R_FIRST) {
+ if (flag == R_FIRST || hashp->cbucket == CURSOR_NOT_SET) {
hashp->cbucket = 0;
hashp->cndx = 1;
hashp->cpage = NULL;
- } else if (hashp->cbucket < 0) { /* R_NEXT */
+ } else if (hashp->cbucket <= CURSOR_OVERFLOW) {
return (ABNORMAL);
}
next_bucket:
@@ -734,7 +738,7 @@
}
hashp->cbucket = bucket;
if ((u_int32_t)hashp->cbucket > hashp->MAX_BUCKET) {
- hashp->cbucket = -1;
+ hashp->cbucket = CURSOR_OVERFLOW;
return (ABNORMAL);
}
} else {
diff --git a/lib/libc/tests/db/dbm_nextkey_test.c b/lib/libc/tests/db/dbm_nextkey_test.c
--- a/lib/libc/tests/db/dbm_nextkey_test.c
+++ b/lib/libc/tests/db/dbm_nextkey_test.c
@@ -45,9 +45,42 @@
dbm_close(db);
}
+ATF_TC(dbm_nextkey_cursor_test);
+ATF_TC_HEAD(dbm_nextkey_cursor_test, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Check that dbm_nextkey acts as if R_FIRST was passed if the cursor is not set");
+}
+
+ATF_TC_BODY(dbm_nextkey_cursor_test, tc)
+{
+ DBM *db;
+ datum key, data;
+
+ data.dptr = "bar";
+ data.dsize = strlen("bar");
+ key.dptr = "foo";
+ key.dsize = strlen("foo");
+
+ db = dbm_open(path, O_RDWR | O_CREAT, 0755);
+ ATF_CHECK(db != NULL);
+ ATF_REQUIRE(atf_utils_file_exists(dbname));
+ ATF_REQUIRE(dbm_store(db, key, data, DBM_INSERT) != -1);
+ dbm_close(db);
+
+ db = dbm_open(path, O_RDWR | O_CREAT, 0755);
+ ATF_CHECK(db != NULL);
+ ATF_REQUIRE(atf_utils_file_exists(dbname));
+ key = dbm_nextkey(db);
+ ATF_REQUIRE(key.dptr != NULL);
+
+ dbm_close(db);
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, dbm_nextkey_test);
+ ATF_TP_ADD_TC(tp, dbm_nextkey_cursor_test);
return (atf_no_error());
}

File Metadata

Mime Type
text/plain
Expires
Mon, Aug 17, 5:04 PM (4 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36860103
Default Alt Text
D57670.diff (2 KB)

Event Timeline