Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This put overload fixes a very major bug. #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

hrissan
Copy link

@hrissan hrissan commented Jun 16, 2017

Consider dbi.put(txn, key, val{data, size});
as val is not an lvalue, the following template overload will be selected.
template<typename K, typename V>
bool put(MDB_txn* const txn,
const K& key,
const V& val,
const unsigned int flags = default_put_flags) {
const lmdb::val k{&key, sizeof(K)};
lmdb::val v{&val, sizeof(V)};
return lmdb::dbi_put(txn, handle(), k, v, flags);
}
Which instead of storing (data, size) will store (&val, sizeof(val))

Consider dbi.put(txn, key, val{data, size});
as val is not an lvalue, the following template overload will be selected.
  template<typename K, typename V>
  bool put(MDB_txn* const txn,
           const K& key,
           const V& val,
           const unsigned int flags = default_put_flags) {
    const lmdb::val k{&key, sizeof(K)};
    lmdb::val v{&val, sizeof(V)};
    return lmdb::dbi_put(txn, handle(), k, v, flags);
  }
Which instead of storing (data, size) will store (&val, sizeof(val))
@hoytech
Copy link

hoytech commented Jul 23, 2020

I agree that these templated methods were a bad idea. I have removed them in my lmdbxx fork, and documented some alternatives in the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants