]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Use uint32_t in MDBGetMaxID and MDBGetRandomID
authorFred Morcos <fred.morcos@open-xchange.com>
Wed, 16 Oct 2024 11:31:09 +0000 (13:31 +0200)
committerFred Morcos <fred.morcos@open-xchange.com>
Wed, 16 Oct 2024 13:57:48 +0000 (15:57 +0200)
ext/lmdb-safe/lmdb-typed.cc
ext/lmdb-safe/lmdb-typed.hh

index e9a2d1e2c089e9b47b60dec425d8edfdb6822c9d..ff63ea8f2c8f80eb2a364159358d5b9e450c5d97 100644 (file)
@@ -1,28 +1,29 @@
 #include "lmdb-typed.hh"
 #include "pdns/dns_random.hh"
 
-unsigned int MDBGetMaxID(MDBRWTransaction& txn, MDBDbi& dbi)
+uint32_t MDBGetMaxID(MDBRWTransaction& txn, MDBDbi& dbi)
 {
   auto cursor = txn->getRWCursor(dbi);
   MDBOutVal maxidval{};
   MDBOutVal maxcontent{};
-  unsigned int maxid{0};
+  uint32_t maxid{0};
   if (cursor.get(maxidval, maxcontent, MDB_LAST) == 0) {
-    maxid = maxidval.getNoStripHeader<unsigned int>();
+    maxid = maxidval.getNoStripHeader<uint32_t>();
   }
   return maxid;
 }
 
-unsigned int MDBGetRandomID(MDBRWTransaction& txn, MDBDbi& dbi)
+uint32_t MDBGetRandomID(MDBRWTransaction& txn, MDBDbi& dbi)
 {
   auto cursor = txn->getRWCursor(dbi);
-  unsigned int newID = 0;
+  uint32_t newID = 0;
   for (int attempts = 0; attempts < 20; attempts++) {
     MDBOutVal key{};
     MDBOutVal content{};
 
-    // dns_random generates a random number in [0..signed_int_max-1]. We add 1 to avoid 0 and allow type_max.
-    // 0 is avoided because the put() interface uses it to mean "please allocate a number for me"
+    // dns_random generates a random number in [0..signed_int_max-1]. We add 1 to avoid 0
+    // and allow type_max. 0 is avoided because the put() interface uses it to mean
+    // "please allocate a number for me".
     newID = dns_random(std::numeric_limits<signed int>::max()) + 1;
     if (cursor.find(MDBInVal(newID), key, content) != 0) {
       return newID;
index a55f67d63aa88b846893b5e18cacd8d2f37e7519..35cdaf1e28a3415eba5e5eecb7726a4b43ef3ac5 100644 (file)
@@ -35,13 +35,13 @@ using LmdbIdVec = std::vector<uint32_t>;
  * Return the highest ID used in a database. Returns 0 for an empty DB. This makes us
  * start everything at ID=1, which might make it possible to treat id 0 as special.
  */
-unsigned int MDBGetMaxID(MDBRWTransaction& txn, MDBDbi& dbi);
+uint32_t MDBGetMaxID(MDBRWTransaction& txn, MDBDbi& dbi);
 
 /**
  * Return a randomly generated ID that is unique and not zero. May throw if the database
  * is very full.
  */
-unsigned int MDBGetRandomID(MDBRWTransaction& txn, MDBDbi& dbi);
+uint32_t MDBGetRandomID(MDBRWTransaction& txn, MDBDbi& dbi);
 
 /**
  * This is our serialization interface. It can be specialized for other types.