Commit 2e776bd3 authored by Howard Chu's avatar Howard Chu
Browse files

More DB checks

parent b834dc05
......@@ -1659,7 +1659,7 @@ mdb_get(MDB_txn *txn, MDB_dbi dbi,
assert(data);
DPRINTF("===> get key [%.*s]", (int)key->mv_size, (char *)key->mv_data);
if (txn == NULL || dbi >= txn->mt_numdbs)
if (txn == NULL || !dbi || dbi >= txn->mt_numdbs)
return EINVAL;
if (key->mv_size == 0 || key->mv_size > MAXKEYSIZE) {
......@@ -2673,7 +2673,7 @@ mdb_del(MDB_txn *txn, MDB_dbi dbi,
assert(key != NULL);
if (txn == NULL || dbi >= txn->mt_numdbs)
if (txn == NULL || !dbi || dbi >= txn->mt_numdbs)
return EINVAL;
if (F_ISSET(txn->mt_flags, MDB_TXN_RDONLY)) {
......@@ -3035,7 +3035,7 @@ mdb_put(MDB_txn *txn, MDB_dbi dbi,
assert(key != NULL);
assert(data != NULL);
if (txn == NULL || dbi >= txn->mt_numdbs)
if (txn == NULL || !dbi || dbi >= txn->mt_numdbs)
return EINVAL;
if (F_ISSET(txn->mt_flags, MDB_TXN_RDONLY)) {
......@@ -3171,3 +3171,30 @@ void mdb_close(MDB_txn *txn, MDB_dbi dbi)
txn->mt_dbxs[dbi].md_name.mv_size = 0;
free(ptr);
}
int mdb_set_compare(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp)
{
if (txn == NULL || !dbi || dbi >= txn->mt_numdbs)
return EINVAL;
txn->mt_dbxs[dbi].md_cmp = cmp;
return MDB_SUCCESS;
}
int mdb_set_dupsort(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp)
{
if (txn == NULL || !dbi || dbi >= txn->mt_numdbs)
return EINVAL;
txn->mt_dbxs[dbi].md_dcmp = cmp;
return MDB_SUCCESS;
}
int mdb_set_relfunc(MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel)
{
if (txn == NULL || !dbi || dbi >= txn->mt_numdbs)
return EINVAL;
txn->mt_dbxs[dbi].md_rel = rel;
return MDB_SUCCESS;
}
......@@ -100,6 +100,7 @@ typedef struct MDB_stat {
int mdbenv_create(MDB_env **env);
int mdbenv_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode);
int mdbenv_stat(MDB_env *env, MDB_stat *stat);
int mdbenv_sync(MDB_env *env);
void mdbenv_close(MDB_env *env);
int mdbenv_get_flags(MDB_env *env, unsigned int *flags);
int mdbenv_get_path(MDB_env *env, const char **path);
......@@ -107,7 +108,6 @@ int mdbenv_set_mapsize(MDB_env *env, size_t size);
int mdbenv_set_maxreaders(MDB_env *env, int readers);
int mdbenv_get_maxreaders(MDB_env *env, int *readers);
int mdbenv_set_maxdbs(MDB_env *env, int dbs);
int mdbenv_sync(MDB_env *env);
int mdb_txn_begin(MDB_env *env, int rdonly, MDB_txn **txn);
int mdb_txn_commit(MDB_txn *txn);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment