The cursor emulation was broken, which led to O on an existing first line of

a file to fail.
Fixes PR bin/39293 by Adam Hoka.
This commit is contained in:
aymeric 2008-08-05 15:49:18 +00:00
parent 7b679f625d
commit 100893232d
2 changed files with 9 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: db.h,v 1.2 2008/05/20 17:53:18 aymeric Exp $ */ /* $NetBSD: db.h,v 1.3 2008/08/05 15:49:18 aymeric Exp $ */
#include <db.h> #include <db.h>
@ -136,6 +136,8 @@ struct __db_new {
struct __dbc_new { struct __dbc_new {
DB *db; DB *db;
db_recno_t pos;
DBT_v1 pos_key;
int (*c_close)(DBC *); int (*c_close)(DBC *);
int (*c_get)(DBC *, DBT *, DBT *, u_int32_t); int (*c_get)(DBC *, DBT *, DBT *, u_int32_t);
int (*c_put)(DBC *, DBT *, DBT *, u_int32_t); int (*c_put)(DBC *, DBT *, DBT *, u_int32_t);

10
dist/nvi/common/db1.c vendored
View File

@ -292,6 +292,8 @@ db1_db_cursor(DB *db, DB_TXN *txn, DBC **cursorp, u_int32_t flags) {
return -1; return -1;
cursor->db = db; cursor->db = db;
cursor->pos_key.data = &cursor->pos;
cursor->pos_key.size = sizeof cursor->pos;
cursor->c_close = db1_dbc_close; cursor->c_close = db1_dbc_close;
cursor->c_get = db1_dbc_get; cursor->c_get = db1_dbc_get;
cursor->c_put = db1_dbc_put; cursor->c_put = db1_dbc_put;
@ -317,18 +319,21 @@ db1_dbc_get(DBC *cursor, DBT *key, DBT *data, u_int32_t flags) {
case DB_SET: case DB_SET:
ret = db_v1->seq(db_v1, (DBT_v1 *) key, (DBT_v1 *) data, ret = db_v1->seq(db_v1, (DBT_v1 *) key, (DBT_v1 *) data,
R_CURSOR); R_CURSOR);
cursor->pos = * (db_recno_t *) key->data;
break; break;
case DB_FIRST: case DB_FIRST:
ret = db_v1->seq(db_v1, (DBT_v1 *) key, (DBT_v1 *) data, ret = db_v1->seq(db_v1, (DBT_v1 *) key, (DBT_v1 *) data,
R_FIRST); R_FIRST);
if (ret == 1) if (ret == 1)
ret = DB_NOTFOUND; ret = DB_NOTFOUND;
cursor->pos = * (db_recno_t *) key->data;
break; break;
case DB_LAST: case DB_LAST:
ret = db_v1->seq(db_v1, (DBT_v1 *) key, (DBT_v1 *) data, ret = db_v1->seq(db_v1, (DBT_v1 *) key, (DBT_v1 *) data,
R_LAST); R_LAST);
if (ret == 1) if (ret == 1)
ret = DB_NOTFOUND; ret = DB_NOTFOUND;
cursor->pos = * (db_recno_t *) key->data;
break; break;
default: default:
abort(); abort();
@ -346,10 +351,7 @@ db1_dbc_put(DBC *cursor, DBT *key, DBT *data, u_int32_t flags) {
assert((flags & ~(DB_BEFORE | DB_AFTER)) == 0); assert((flags & ~(DB_BEFORE | DB_AFTER)) == 0);
if (db_v1->seq(db_v1, (DBT_v1 *) key, (DBT_v1 *) &data1, R_CURSOR) != 0) ret = db_v1->put(db_v1, &cursor->pos_key, (DBT_v1 *) data,
return -1;
ret = db_v1->put(db_v1, (DBT_v1 *) key, (DBT_v1 *) data,
flags == DB_BEFORE? R_IBEFORE : R_IAFTER); flags == DB_BEFORE? R_IBEFORE : R_IAFTER);
return ret == -1? errno : ret; return ret == -1? errno : ret;