https://bugs.openldap.org/show_bug.cgi?id=8502
--- Comment #2 from Howard Chu hyc@openldap.org --- (In reply to Hallvard Furuseth from comment #0)
Full_Name: Hallvard B Furuseth Version: mdb.master, 26e226b2a8cdba4208eabca394537900c4eda3b3 OS: URL: Submission from: (NULL) (81.191.45.31) Submitted by: hallvard
mdb_cursor_count() has code to return MDB_NOTFOUND if !mc_snum, but it comes after if (! ... C_INITIALIZED) return EINVAL.
It sounds like the NOTFOUND test should just be deleted then, because it's always unreachable.
When a DB is emptied, all cursors on it are de-initialized since there is nothing for the cursors to point to. In an uninitialized cursor, none of the other state is meaningful, so mc->mc_snum is irrelevant.
Changing the order of the tests would mean you get MDB_NOTFOUND even on a cursor on a non-empty DB, if it has never been used yet. Is that actually a more sensible result in that case?